diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
commit | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch) | |
tree | ec41ed70ffca97240e76f9a78bb2dedba28f310c /test/std/input.output/iostream.format | |
parent | f857581820d15e410e9945d2fcd5f7163be25a96 (diff) |
Notes
Diffstat (limited to 'test/std/input.output/iostream.format')
122 files changed, 8750 insertions, 0 deletions
diff --git a/test/std/input.output/iostream.format/ext.manip/get_money.pass.cpp b/test/std/input.output/iostream.format/ext.manip/get_money.pass.cpp new file mode 100644 index 0000000000000..1ea1d780c50ff --- /dev/null +++ b/test/std/input.output/iostream.format/ext.manip/get_money.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// template <class moneyT> T7 get_money(moneyT& mon, bool intl = false); + +// REQUIRES: locale.en_US.UTF-8 + +#include <iomanip> +#include <cassert> + +#include "platform_support.h" // locale name macros + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } +}; + +int main() +{ + { + testbuf<char> sb(" -$1,234,567.89"); + std::istream is(&sb); + is.imbue(std::locale(LOCALE_en_US_UTF_8)); + long double x = 0; + is >> std::get_money(x, false); + assert(x == -123456789); + } + { + testbuf<char> sb(" -USD 1,234,567.89"); + std::istream is(&sb); + is.imbue(std::locale(LOCALE_en_US_UTF_8)); + long double x = 0; + is >> std::get_money(x, true); + assert(x == -123456789); + } + { + testbuf<wchar_t> sb(L" -$1,234,567.89"); + std::wistream is(&sb); + is.imbue(std::locale(LOCALE_en_US_UTF_8)); + long double x = 0; + is >> std::get_money(x, false); + assert(x == -123456789); + } + { + testbuf<wchar_t> sb(L" -USD 1,234,567.89"); + std::wistream is(&sb); + is.imbue(std::locale(LOCALE_en_US_UTF_8)); + long double x = 0; + is >> std::get_money(x, true); + assert(x == -123456789); + } +} diff --git a/test/std/input.output/iostream.format/ext.manip/get_time.pass.cpp b/test/std/input.output/iostream.format/ext.manip/get_time.pass.cpp new file mode 100644 index 0000000000000..17ff642dc46d2 --- /dev/null +++ b/test/std/input.output/iostream.format/ext.manip/get_time.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// template <class charT> T9 get_time(struct tm* tmb, const charT* fmt); + +#include <iomanip> +#include <cassert> + +#include "platform_support.h" // locale name macros + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } +}; + +int main() +{ + { + testbuf<char> sb(" Sat Dec 31 23:55:59 2061"); + std::istream is(&sb); + is.imbue(std::locale(LOCALE_en_US_UTF_8)); + std::tm t = {0}; + is >> std::get_time(&t, "%a %b %d %H:%M:%S %Y"); + assert(t.tm_sec == 59); + assert(t.tm_min == 55); + assert(t.tm_hour == 23); + assert(t.tm_mday == 31); + assert(t.tm_mon == 11); + assert(t.tm_year == 161); + assert(t.tm_wday == 6); + assert(is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" Sat Dec 31 23:55:59 2061"); + std::wistream is(&sb); + is.imbue(std::locale(LOCALE_en_US_UTF_8)); + std::tm t = {0}; + is >> std::get_time(&t, L"%a %b %d %H:%M:%S %Y"); + assert(t.tm_sec == 59); + assert(t.tm_min == 55); + assert(t.tm_hour == 23); + assert(t.tm_mday == 31); + assert(t.tm_mon == 11); + assert(t.tm_year == 161); + assert(t.tm_wday == 6); + assert(is.eof()); + assert(!is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp b/test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp new file mode 100644 index 0000000000000..a00cf139be938 --- /dev/null +++ b/test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// template <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false); + +// REQUIRES: locale.en_US.UTF-8 + +#include <iomanip> +#include <cassert> + +#include "platform_support.h" // locale name macros + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + os.imbue(std::locale(LOCALE_en_US_UTF_8)); + showbase(os); + long double x = -123456789; + os << std::put_money(x, false); + assert(sb.str() == "-$1,234,567.89"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.imbue(std::locale(LOCALE_en_US_UTF_8)); + showbase(os); + long double x = -123456789; + os << std::put_money(x, true); + assert(sb.str() == "-USD 1,234,567.89"); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.imbue(std::locale(LOCALE_en_US_UTF_8)); + showbase(os); + long double x = -123456789; + os << std::put_money(x, false); + assert(sb.str() == L"-$1,234,567.89"); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.imbue(std::locale(LOCALE_en_US_UTF_8)); + showbase(os); + long double x = -123456789; + os << std::put_money(x, true); + assert(sb.str() == L"-USD 1,234,567.89"); + } +} diff --git a/test/std/input.output/iostream.format/ext.manip/put_time.pass.cpp b/test/std/input.output/iostream.format/ext.manip/put_time.pass.cpp new file mode 100644 index 0000000000000..52a98a1b5688c --- /dev/null +++ b/test/std/input.output/iostream.format/ext.manip/put_time.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt); + +#include <iomanip> +#include <cassert> + +#include "platform_support.h" // locale name macros + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + os.imbue(std::locale(LOCALE_en_US_UTF_8)); + std::tm t = {0}; + t.tm_sec = 59; + t.tm_min = 55; + t.tm_hour = 23; + t.tm_mday = 31; + t.tm_mon = 11; + t.tm_year = 161; + t.tm_wday = 6; + t.tm_isdst = 0; + os << std::put_time(&t, "%a %b %d %H:%M:%S %Y"); + assert(sb.str() == "Sat Dec 31 23:55:59 2061"); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.imbue(std::locale(LOCALE_en_US_UTF_8)); + std::tm t = {0}; + t.tm_sec = 59; + t.tm_min = 55; + t.tm_hour = 23; + t.tm_mday = 31; + t.tm_mon = 11; + t.tm_year = 161; + t.tm_wday = 6; + os << std::put_time(&t, L"%a %b %d %H:%M:%S %Y"); + assert(sb.str() == L"Sat Dec 31 23:55:59 2061"); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.assign/member_swap.pass.cpp b/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.assign/member_swap.pass.cpp new file mode 100644 index 0000000000000..f4d425728b773 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.assign/member_swap.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_iostream; + +// void swap(basic_iostream& rhs); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +template <class CharT> +struct test_iostream + : public std::basic_iostream<CharT> +{ + typedef std::basic_iostream<CharT> base; + test_iostream(testbuf<CharT>* sb) : base(sb) {} + + void swap(test_iostream& s) {base::swap(s);} +}; + +int main() +{ + { + testbuf<char> sb1; + testbuf<char> sb2; + test_iostream<char> is1(&sb1); + test_iostream<char> is2(&sb2); + is1.swap(is2); + assert(is1.rdbuf() == &sb1); + assert(is1.tie() == 0); + assert(is1.fill() == ' '); + assert(is1.rdstate() == is1.goodbit); + assert(is1.exceptions() == is1.goodbit); + assert(is1.flags() == (is1.skipws | is1.dec)); + assert(is1.precision() == 6); + assert(is1.getloc().name() == "C"); + assert(is2.rdbuf() == &sb2); + assert(is2.tie() == 0); + assert(is2.fill() == ' '); + assert(is2.rdstate() == is2.goodbit); + assert(is2.exceptions() == is2.goodbit); + assert(is2.flags() == (is2.skipws | is2.dec)); + assert(is2.precision() == 6); + assert(is2.getloc().name() == "C"); + } + { + testbuf<wchar_t> sb1; + testbuf<wchar_t> sb2; + test_iostream<wchar_t> is1(&sb1); + test_iostream<wchar_t> is2(&sb2); + is1.swap(is2); + assert(is1.rdbuf() == &sb1); + assert(is1.tie() == 0); + assert(is1.fill() == ' '); + assert(is1.rdstate() == is1.goodbit); + assert(is1.exceptions() == is1.goodbit); + assert(is1.flags() == (is1.skipws | is1.dec)); + assert(is1.precision() == 6); + assert(is1.getloc().name() == "C"); + assert(is2.rdbuf() == &sb2); + assert(is2.tie() == 0); + assert(is2.fill() == ' '); + assert(is2.rdstate() == is2.goodbit); + assert(is2.exceptions() == is2.goodbit); + assert(is2.flags() == (is2.skipws | is2.dec)); + assert(is2.precision() == 6); + assert(is2.getloc().name() == "C"); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.assign/move_assign.pass.cpp b/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.assign/move_assign.pass.cpp new file mode 100644 index 0000000000000..2032e935bfacc --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.assign/move_assign.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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_iostream; + +// basic_iostream& operator=(basic_iostream&& rhs); + +#include <istream> +#include <cassert> + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +template <class CharT> +struct test_iostream + : public std::basic_iostream<CharT> +{ + typedef std::basic_iostream<CharT> base; + test_iostream(testbuf<CharT>* sb) : base(sb) {} + + test_iostream& operator=(test_iostream&& s) + {base::operator=(std::move(s)); return *this;} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + testbuf<char> sb1; + testbuf<char> sb2; + test_iostream<char> is1(&sb1); + test_iostream<char> is2(&sb2); + is2 = (std::move(is1)); + assert(is1.rdbuf() == &sb1); + assert(is1.tie() == 0); + assert(is1.fill() == ' '); + assert(is1.rdstate() == is1.goodbit); + assert(is1.exceptions() == is1.goodbit); + assert(is1.flags() == (is1.skipws | is1.dec)); + assert(is1.precision() == 6); + assert(is1.getloc().name() == "C"); + assert(is2.rdbuf() == &sb2); + assert(is2.tie() == 0); + assert(is2.fill() == ' '); + assert(is2.rdstate() == is2.goodbit); + assert(is2.exceptions() == is2.goodbit); + assert(is2.flags() == (is2.skipws | is2.dec)); + assert(is2.precision() == 6); + assert(is2.getloc().name() == "C"); + } + { + testbuf<wchar_t> sb1; + testbuf<wchar_t> sb2; + test_iostream<wchar_t> is1(&sb1); + test_iostream<wchar_t> is2(&sb2); + is2 = (std::move(is1)); + assert(is1.rdbuf() == &sb1); + assert(is1.tie() == 0); + assert(is1.fill() == ' '); + assert(is1.rdstate() == is1.goodbit); + assert(is1.exceptions() == is1.goodbit); + assert(is1.flags() == (is1.skipws | is1.dec)); + assert(is1.precision() == 6); + assert(is1.getloc().name() == "C"); + assert(is2.rdbuf() == &sb2); + assert(is2.tie() == 0); + assert(is2.fill() == ' '); + assert(is2.rdstate() == is2.goodbit); + assert(is2.exceptions() == is2.goodbit); + assert(is2.flags() == (is2.skipws | is2.dec)); + assert(is2.precision() == 6); + assert(is2.getloc().name() == "C"); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.cons/move.pass.cpp b/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.cons/move.pass.cpp new file mode 100644 index 0000000000000..c0592e927c8f6 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.cons/move.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_iostream; + +// basic_iostream(basic_iostream&& rhs); + +#include <istream> +#include <cassert> + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +template <class CharT> +struct test_iostream + : public std::basic_iostream<CharT> +{ + typedef std::basic_iostream<CharT> base; + test_iostream(testbuf<CharT>* sb) : base(sb) {} + + test_iostream(test_iostream&& s) + : base(std::move(s)) {} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + testbuf<char> sb; + test_iostream<char> is1(&sb); + test_iostream<char> is(std::move(is1)); + assert(is1.rdbuf() == &sb); + assert(is1.gcount() == 0); + assert(is.gcount() == 0); + assert(is.rdbuf() == 0); + assert(is.tie() == 0); + assert(is.fill() == ' '); + assert(is.rdstate() == is.goodbit); + assert(is.exceptions() == is.goodbit); + assert(is.flags() == (is.skipws | is.dec)); + assert(is.precision() == 6); + assert(is.getloc().name() == "C"); + } + { + testbuf<wchar_t> sb; + test_iostream<wchar_t> is1(&sb); + test_iostream<wchar_t> is(std::move(is1)); + assert(is1.gcount() == 0); + assert(is.gcount() == 0); + assert(is1.rdbuf() == &sb); + assert(is.rdbuf() == 0); + assert(is.tie() == 0); + assert(is.fill() == L' '); + assert(is.rdstate() == is.goodbit); + assert(is.exceptions() == is.goodbit); + assert(is.flags() == (is.skipws | is.dec)); + assert(is.precision() == 6); + assert(is.getloc().name() == "C"); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.cons/streambuf.pass.cpp b/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.cons/streambuf.pass.cpp new file mode 100644 index 0000000000000..dacc8d26d76e1 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.cons/streambuf.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_iostream; + +// explicit basic_iostream(basic_streambuf<charT,traits>* sb); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +int main() +{ + { + testbuf<char> sb; + std::basic_iostream<char> is(&sb); + assert(is.rdbuf() == &sb); + assert(is.tie() == 0); + assert(is.fill() == ' '); + assert(is.rdstate() == is.goodbit); + assert(is.exceptions() == is.goodbit); + assert(is.flags() == (is.skipws | is.dec)); + assert(is.precision() == 6); + assert(is.getloc().name() == "C"); + assert(is.gcount() == 0); + } + { + testbuf<wchar_t> sb; + std::basic_iostream<wchar_t> is(&sb); + assert(is.rdbuf() == &sb); + assert(is.tie() == 0); + assert(is.fill() == L' '); + assert(is.rdstate() == is.goodbit); + assert(is.exceptions() == is.goodbit); + assert(is.flags() == (is.skipws | is.dec)); + assert(is.precision() == 6); + assert(is.getloc().name() == "C"); + assert(is.gcount() == 0); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.dest/nothing_to_do.pass.cpp b/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.dest/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/iostreamclass/iostream.dest/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/input.output/iostream.format/input.streams/iostreamclass/types.pass.cpp b/test/std/input.output/iostream.format/input.streams/iostreamclass/types.pass.cpp new file mode 100644 index 0000000000000..6890f1cf7c170 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/iostreamclass/types.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_iostream : +// public basic_istream<charT,traits>, +// public basic_ostream<charT,traits> +// { +// public: +// // types: +// typedef charT char_type; +// typedef traits traits_type; +// typedef typename traits_type::int_type int_type; +// typedef typename traits_type::pos_type pos_type; +// typedef typename traits_type::off_type off_type; + +#include <istream> +#include <type_traits> + +int main() +{ + static_assert((std::is_base_of<std::basic_istream<char>, std::basic_iostream<char> >::value), ""); + static_assert((std::is_base_of<std::basic_ostream<char>, std::basic_iostream<char> >::value), ""); + static_assert((std::is_same<std::basic_iostream<char>::char_type, char>::value), ""); + static_assert((std::is_same<std::basic_iostream<char>::traits_type, std::char_traits<char> >::value), ""); + static_assert((std::is_same<std::basic_iostream<char>::int_type, std::char_traits<char>::int_type>::value), ""); + static_assert((std::is_same<std::basic_iostream<char>::pos_type, std::char_traits<char>::pos_type>::value), ""); + static_assert((std::is_same<std::basic_iostream<char>::off_type, std::char_traits<char>::off_type>::value), ""); +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/bool.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/bool.pass.cpp new file mode 100644 index 0000000000000..beaebfe8566d3 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/bool.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(bool& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + bool n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + bool n = true; + is >> n; + assert(n == false); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 1 "); + std::istream is(&sb); + bool n = 0; + is >> n; + assert(n == true); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" 1 "); + std::wistream is(&sb); + bool n = 0; + is >> n; + assert(n == true); + assert(!is.eof()); + assert(!is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/double.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/double.pass.cpp new file mode 100644 index 0000000000000..1c8716e86e47b --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/double.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(double& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + double n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + double n = 10; + is >> n; + assert(n == 0); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 123 "); + std::istream is(&sb); + double n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" -123.5 "); + std::wistream is(&sb); + double n = 10; + is >> n; + assert(n == -123.5); + assert(!is.eof()); + assert(!is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/float.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/float.pass.cpp new file mode 100644 index 0000000000000..f5ef23e654a1b --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/float.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(float& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + float n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + float n = 10; + is >> n; + assert(n == 0); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 123 "); + std::istream is(&sb); + float n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" -123.5 "); + std::wistream is(&sb); + float n = 10; + is >> n; + assert(n == -123.5); + assert(!is.eof()); + assert(!is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/int.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/int.pass.cpp new file mode 100644 index 0000000000000..25687db16f37e --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/int.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(int& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + int n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + int n = 10; + is >> n; + assert(n == 0); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 123 "); + std::istream is(&sb); + int n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" -1234567890123456 "); + std::wistream is(&sb); + int n = 10; + is >> n; + assert(n == std::numeric_limits<int>::min()); + assert(!is.eof()); + assert( is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long.pass.cpp new file mode 100644 index 0000000000000..4b4765452c687 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(long& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + long n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + long n = 10; + is >> n; + assert(n == 0); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 123 "); + std::istream is(&sb); + long n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" -123 "); + std::wistream is(&sb); + long n = 10; + is >> n; + assert(n == -123); + assert(!is.eof()); + assert(!is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_double.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_double.pass.cpp new file mode 100644 index 0000000000000..cc70faed6c23a --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_double.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(long double& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + long double n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + long double n = 10; + is >> n; + assert(n == 0); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 123 "); + std::istream is(&sb); + long double n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" -123.5 "); + std::wistream is(&sb); + long double n = 10; + is >> n; + assert(n == -123.5); + assert(!is.eof()); + assert(!is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_long.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_long.pass.cpp new file mode 100644 index 0000000000000..c37e175162487 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_long.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(long long& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + long long n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + long long n = 10; + is >> n; + assert(n == 0); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 123 "); + std::istream is(&sb); + long long n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" -123 "); + std::wistream is(&sb); + long long n = 10; + is >> n; + assert(n == -123); + assert(!is.eof()); + assert(!is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/pointer.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/pointer.pass.cpp new file mode 100644 index 0000000000000..52b35666424af --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/pointer.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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(void*& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + void* n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + void* n = (void*)1; + is >> n; + assert(n == 0); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 1 "); + std::istream is(&sb); + void* n = 0; + is >> n; + assert(n == (void*)1); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" 1 "); + std::wistream is(&sb); + void* n = 0; + is >> n; + assert(n == (void*)1); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb("12345678"); + std::istream is(&sb); + void* n = 0; + is >> n; + assert(n == (void*)0x12345678); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L"12345678"); + std::wistream is(&sb); + void* n = 0; + is >> n; + assert(n == (void*)0x12345678); + assert( is.eof()); + assert(!is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/short.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/short.pass.cpp new file mode 100644 index 0000000000000..62e44f542a649 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/short.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(short& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + short n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + short n = 10; + is >> n; + assert(n == 0); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 123 "); + std::istream is(&sb); + short n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" -1234567890 "); + std::wistream is(&sb); + short n = 10; + is >> n; + assert(n == std::numeric_limits<short>::min()); + assert(!is.eof()); + assert( is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_int.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_int.pass.cpp new file mode 100644 index 0000000000000..6f1091690da1e --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_int.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(unsigned int& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + unsigned int n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + unsigned int n = 10; + is >> n; + assert(n == 0); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 123 "); + std::istream is(&sb); + unsigned int n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" 123 "); + std::wistream is(&sb); + unsigned int n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long.pass.cpp new file mode 100644 index 0000000000000..eb8a7231ffca1 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(unsigned long& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + unsigned long n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + unsigned long n = 10; + is >> n; + assert(n == 0); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 123 "); + std::istream is(&sb); + unsigned long n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" 123 "); + std::wistream is(&sb); + unsigned long n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long_long.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long_long.pass.cpp new file mode 100644 index 0000000000000..1db250ed463a9 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long_long.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(unsigned long long& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + unsigned long long n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + unsigned long long n = 10; + is >> n; + assert(n == 0); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 123 "); + std::istream is(&sb); + unsigned long long n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" 123 "); + std::wistream is(&sb); + unsigned long long n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_short.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_short.pass.cpp new file mode 100644 index 0000000000000..78fdc66388235 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_short.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// operator>>(unsigned short& val); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + std::istream is((std::streambuf*)0); + unsigned short n = 0; + is >> n; + assert(is.fail()); + } + { + testbuf<char> sb("0"); + std::istream is(&sb); + unsigned short n = 10; + is >> n; + assert(n == 0); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<char> sb(" 123 "); + std::istream is(&sb); + unsigned short n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" 123 "); + std::wistream is(&sb); + unsigned short n = 10; + is >> n; + assert(n == 123); + assert(!is.eof()); + assert(!is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.reqmts/tested_elsewhere.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.reqmts/tested_elsewhere.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.reqmts/tested_elsewhere.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/basic_ios.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/basic_ios.pass.cpp new file mode 100644 index 0000000000000..0d4516d555670 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/basic_ios.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// basic_istream<charT,traits>& operator>>(basic_ios<charT,traits>& +// (*pf)(basic_ios<charT,traits>&)); + +#include <istream> +#include <cassert> + +int f_called = 0; + +template <class CharT> +std::basic_ios<CharT>& +f(std::basic_ios<CharT>& is) +{ + ++f_called; + return is; +} + +int main() +{ + { + std::istream is((std::streambuf*)0); + is >> f; + assert(f_called == 1); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/chart.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/chart.pass.cpp new file mode 100644 index 0000000000000..b5068220cffd5 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/chart.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template<class charT, class traits> +// basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&& in, charT& c); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" "); + std::istream is(&sb); + char c = 'z'; + is >> c; + assert( is.eof()); + assert( is.fail()); + assert(c == 'z'); + } + { + testbuf<char> sb(" abcdefghijk "); + std::istream is(&sb); + char c; + is >> c; + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'a'); + is >> c; + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'b'); + is >> c; + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'c'); + } + { + testbuf<wchar_t> sb(L" abc"); + std::wistream is(&sb); + wchar_t c; + is >> c; + assert(!is.eof()); + assert(!is.fail()); + assert(c == L'a'); + is >> c; + assert(!is.eof()); + assert(!is.fail()); + assert(c == L'b'); + is >> c; + assert(!is.eof()); + assert(!is.fail()); + assert(c == L'c'); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/ios_base.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/ios_base.pass.cpp new file mode 100644 index 0000000000000..d4cb2bb13b2f4 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/ios_base.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// basic_istream<charT,traits>& operator>>(ios_base& (*pf)(ios_base&)); + +#include <istream> +#include <cassert> + +int f_called = 0; + +std::ios_base& +f(std::ios_base& is) +{ + ++f_called; + return is; +} + +int main() +{ + { + std::istream is((std::streambuf*)0); + is >> f; + assert(f_called == 1); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/istream.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/istream.pass.cpp new file mode 100644 index 0000000000000..4c3aef491ea65 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/istream.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>& +// (*pf)(basic_istream<charT,traits>&)); + +#include <istream> +#include <cassert> + +int f_called = 0; + +template <class CharT> +std::basic_istream<CharT>& +f(std::basic_istream<CharT>& is) +{ + ++f_called; + return is; +} + +int main() +{ + { + std::istream is((std::streambuf*)0); + is >> f; + assert(f_called == 1); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char.pass.cpp new file mode 100644 index 0000000000000..a02fe2c51a6d4 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char.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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template<class traits> +// basic_istream<char,traits>& operator>>(basic_istream<char,traits>&& in, signed char& c); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" "); + std::istream is(&sb); + signed char c = 'z'; + is >> c; + assert( is.eof()); + assert( is.fail()); + assert(c == 'z'); + } + { + testbuf<char> sb(" abcdefghijk "); + std::istream is(&sb); + signed char c; + is >> c; + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'a'); + is >> c; + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'b'); + is >> c; + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'c'); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char_pointer.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char_pointer.pass.cpp new file mode 100644 index 0000000000000..70f1c20108fca --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char_pointer.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template<class traits> +// basic_istream<char,traits>& operator>>(basic_istream<char,traits>&& in, signed char* s); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" abcdefghijk "); + std::istream is(&sb); + signed char s[20]; + is >> s; + assert(!is.eof()); + assert(!is.fail()); + assert(std::string((char*)s) == "abcdefghijk"); + } + { + testbuf<char> sb(" abcdefghijk "); + std::istream is(&sb); + is.width(4); + signed char s[20]; + is >> s; + assert(!is.eof()); + assert(!is.fail()); + assert(std::string((char*)s) == "abc"); + assert(is.width() == 0); + } + { + testbuf<char> sb(" abcdefghijk"); + std::istream is(&sb); + signed char s[20]; + is >> s; + assert( is.eof()); + assert(!is.fail()); + assert(std::string((char*)s) == "abcdefghijk"); + assert(is.width() == 0); + } + { + testbuf<char> sb(" abcdefghijk"); + std::istream is(&sb); + signed char s[20]; + is.width(1); + is >> s; + assert(!is.eof()); + assert( is.fail()); + assert(std::string((char*)s) == ""); + assert(is.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp new file mode 100644 index 0000000000000..29ed68e9770c2 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// basic_istream<charT,traits>& operator<<(basic_streambuf<charT,traits>* sb); + +#include <istream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + testbuf(const std::basic_string<CharT>& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + testbuf<char> sb("testing..."); + std::istream is(&sb); + testbuf<char> sb2; + is >> &sb2; + assert(sb2.str() == "testing..."); + assert(is.gcount() == 10); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char.pass.cpp new file mode 100644 index 0000000000000..8f19cea7b882e --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char.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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template<class traits> +// basic_istream<char,traits>& operator>>(basic_istream<char,traits>&& in, unsigned char& c); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" "); + std::istream is(&sb); + unsigned char c = 'z'; + is >> c; + assert( is.eof()); + assert( is.fail()); + assert(c == 'z'); + } + { + testbuf<char> sb(" abcdefghijk "); + std::istream is(&sb); + unsigned char c; + is >> c; + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'a'); + is >> c; + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'b'); + is >> c; + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'c'); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char_pointer.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char_pointer.pass.cpp new file mode 100644 index 0000000000000..07fa5a79e8f28 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char_pointer.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template<class traits> +// basic_istream<char,traits>& operator>>(basic_istream<char,traits>&& in, unsigned char* s); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" abcdefghijk "); + std::istream is(&sb); + unsigned char s[20]; + is >> s; + assert(!is.eof()); + assert(!is.fail()); + assert(std::string((char*)s) == "abcdefghijk"); + } + { + testbuf<char> sb(" abcdefghijk "); + std::istream is(&sb); + is.width(4); + unsigned char s[20]; + is >> s; + assert(!is.eof()); + assert(!is.fail()); + assert(std::string((char*)s) == "abc"); + assert(is.width() == 0); + } + { + testbuf<char> sb(" abcdefghijk"); + std::istream is(&sb); + unsigned char s[20]; + is >> s; + assert( is.eof()); + assert(!is.fail()); + assert(std::string((char*)s) == "abcdefghijk"); + assert(is.width() == 0); + } + { + testbuf<char> sb(" abcdefghijk"); + std::istream is(&sb); + unsigned char s[20]; + is.width(1); + is >> s; + assert(!is.eof()); + assert( is.fail()); + assert(std::string((char*)s) == ""); + assert(is.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/wchar_t_pointer.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/wchar_t_pointer.pass.cpp new file mode 100644 index 0000000000000..a00c7a1dda381 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/wchar_t_pointer.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template<class charT, class traits> +// basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&& in, charT* s); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" abcdefghijk "); + std::istream is(&sb); + char s[20]; + is >> s; + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s) == "abcdefghijk"); + } + { + testbuf<wchar_t> sb(L" abcdefghijk "); + std::wistream is(&sb); + is.width(4); + wchar_t s[20]; + is >> s; + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L"abc"); + assert(is.width() == 0); + } + { + testbuf<wchar_t> sb(L" abcdefghijk"); + std::wistream is(&sb); + wchar_t s[20]; + is >> s; + assert( is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L"abcdefghijk"); + assert(is.width() == 0); + } + { + testbuf<char> sb(" abcdefghijk"); + std::istream is(&sb); + char s[20]; + is.width(1); + is >> s; + assert(!is.eof()); + assert( is.fail()); + assert(std::string(s) == ""); + assert(is.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.formatted/nothing_to_do.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.formatted/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.formatted/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.manip/ws.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.manip/ws.pass.cpp new file mode 100644 index 0000000000000..3c8159a6d7cb2 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.manip/ws.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits> +// basic_istream<charT,traits>& +// ws(basic_istream<charT,traits>& is); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" 123"); + std::istream is(&sb); + ws(is); + assert(is.good()); + assert(is.peek() == '1'); + } + { + testbuf<wchar_t> sb(L" 123"); + std::wistream is(&sb); + ws(is); + assert(is.good()); + assert(is.peek() == L'1'); + } + { + testbuf<char> sb(" "); + std::istream is(&sb); + ws(is); + assert(!is.fail()); + assert(is.eof()); + ws(is); + assert(is.eof()); + assert(is.fail()); + } + { + testbuf<wchar_t> sb(L" "); + std::wistream is(&sb); + ws(is); + assert(!is.fail()); + assert(is.eof()); + ws(is); + assert(is.eof()); + assert(is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.rvalue/rvalue.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.rvalue/rvalue.pass.cpp new file mode 100644 index 0000000000000..5b7664e3f55cd --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.rvalue/rvalue.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits, class T> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>&& is, T& x); + +#include <istream> +#include <cassert> + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + testbuf<char> sb(" 123"); + int i = 0; + std::istream(&sb) >> i; + assert(i == 123); + } + { + testbuf<wchar_t> sb(L" 123"); + int i = 0; + std::wistream(&sb) >> i; + assert(i == 123); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/get.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/get.pass.cpp new file mode 100644 index 0000000000000..41a721d50f13f --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/get.pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// int_type get(); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" "); + std::istream is(&sb); + char c = is.get(); + assert(!is.eof()); + assert(!is.fail()); + assert(c == ' '); + assert(is.gcount() == 1); + } + { + testbuf<char> sb(" abc"); + std::istream is(&sb); + char c = is.get(); + assert(!is.eof()); + assert(!is.fail()); + assert(c == ' '); + assert(is.gcount() == 1); + c = is.get(); + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'a'); + assert(is.gcount() == 1); + c = is.get(); + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'b'); + assert(is.gcount() == 1); + c = is.get(); + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'c'); + assert(is.gcount() == 1); + } + { + testbuf<wchar_t> sb(L" abc"); + std::wistream is(&sb); + wchar_t c = is.get(); + assert(!is.eof()); + assert(!is.fail()); + assert(c == L' '); + assert(is.gcount() == 1); + c = is.get(); + assert(!is.eof()); + assert(!is.fail()); + assert(c == L'a'); + assert(is.gcount() == 1); + c = is.get(); + assert(!is.eof()); + assert(!is.fail()); + assert(c == L'b'); + assert(is.gcount() == 1); + c = is.get(); + assert(!is.eof()); + assert(!is.fail()); + assert(c == L'c'); + assert(is.gcount() == 1); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_chart.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_chart.pass.cpp new file mode 100644 index 0000000000000..cf06e343bcc2a --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_chart.pass.cpp @@ -0,0 +1,103 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& get(char_type& c); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" "); + std::istream is(&sb); + char c; + is.get(c); + assert(!is.eof()); + assert(!is.fail()); + assert(c == ' '); + assert(is.gcount() == 1); + } + { + testbuf<char> sb(" abc"); + std::istream is(&sb); + char c; + is.get(c); + assert(!is.eof()); + assert(!is.fail()); + assert(c == ' '); + assert(is.gcount() == 1); + is.get(c); + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'a'); + assert(is.gcount() == 1); + is.get(c); + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'b'); + assert(is.gcount() == 1); + is.get(c); + assert(!is.eof()); + assert(!is.fail()); + assert(c == 'c'); + assert(is.gcount() == 1); + } + { + testbuf<wchar_t> sb(L" abc"); + std::wistream is(&sb); + wchar_t c; + is.get(c); + assert(!is.eof()); + assert(!is.fail()); + assert(c == L' '); + assert(is.gcount() == 1); + is.get(c); + assert(!is.eof()); + assert(!is.fail()); + assert(c == L'a'); + assert(is.gcount() == 1); + is.get(c); + assert(!is.eof()); + assert(!is.fail()); + assert(c == L'b'); + assert(is.gcount() == 1); + is.get(c); + assert(!is.eof()); + assert(!is.fail()); + assert(c == L'c'); + assert(is.gcount() == 1); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size.pass.cpp new file mode 100644 index 0000000000000..1691a2d2de14f --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size.pass.cpp @@ -0,0 +1,99 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& get(char_type* s, streamsize n); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" \n \n "); + std::istream is(&sb); + char s[5]; + is.get(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 2); + is.get(s, 5); + assert(!is.eof()); + assert( is.fail()); + assert(std::string(s) == ""); + assert(is.gcount() == 0); + is.clear(); + assert(is.get() == '\n'); + is.get(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 4); + assert(is.get() == '\n'); + is.get(s, 5); + assert( is.eof()); + assert(!is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 1); + } + { + testbuf<wchar_t> sb(L" \n \n "); + std::wistream is(&sb); + wchar_t s[5]; + is.get(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 2); + is.get(s, 5); + assert(!is.eof()); + assert( is.fail()); + assert(std::wstring(s) == L""); + assert(is.gcount() == 0); + is.clear(); + assert(is.get() == L'\n'); + is.get(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 4); + assert(is.get() == L'\n'); + is.get(s, 5); + assert( is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 1); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size_chart.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size_chart.pass.cpp new file mode 100644 index 0000000000000..c9389ec9dad55 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size_chart.pass.cpp @@ -0,0 +1,99 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& get(char_type* s, streamsize n, char_type delim); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" * * "); + std::istream is(&sb); + char s[5]; + is.get(s, 5, '*'); + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 2); + is.get(s, 5, '*'); + assert(!is.eof()); + assert( is.fail()); + assert(std::string(s) == ""); + assert(is.gcount() == 0); + is.clear(); + assert(is.get() == '*'); + is.get(s, 5, '*'); + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 4); + assert(is.get() == '*'); + is.get(s, 5, '*'); + assert( is.eof()); + assert(!is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 1); + } + { + testbuf<wchar_t> sb(L" * * "); + std::wistream is(&sb); + wchar_t s[5]; + is.get(s, 5, L'*'); + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 2); + is.get(s, 5, L'*'); + assert(!is.eof()); + assert( is.fail()); + assert(std::wstring(s) == L""); + assert(is.gcount() == 0); + is.clear(); + assert(is.get() == L'*'); + is.get(s, 5, L'*'); + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 4); + assert(is.get() == L'*'); + is.get(s, 5, L'*'); + assert( is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 1); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf.pass.cpp new file mode 100644 index 0000000000000..7a55f847d7349 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb); + +#include <istream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + testbuf(const std::basic_string<CharT>& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + testbuf<char> sb("testing\n..."); + std::istream is(&sb); + testbuf<char> sb2; + is.get(sb2); + assert(sb2.str() == "testing"); + assert(is.good()); + assert(is.gcount() == 7); + assert(is.get() == '\n'); + is.get(sb2); + assert(sb2.str() == "testing..."); + assert(is.eof()); + assert(!is.fail()); + assert(is.gcount() == 3); + } + { + testbuf<wchar_t> sb(L"testing\n..."); + std::wistream is(&sb); + testbuf<wchar_t> sb2; + is.get(sb2); + assert(sb2.str() == L"testing"); + assert(is.good()); + assert(is.gcount() == 7); + assert(is.get() == L'\n'); + is.get(sb2); + assert(sb2.str() == L"testing..."); + assert(is.eof()); + assert(!is.fail()); + assert(is.gcount() == 3); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf_chart.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf_chart.pass.cpp new file mode 100644 index 0000000000000..cbc007587d5e4 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf_chart.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb, +// char_type delim); + +#include <istream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + testbuf(const std::basic_string<CharT>& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + testbuf<char> sb("testing*..."); + std::istream is(&sb); + testbuf<char> sb2; + is.get(sb2, '*'); + assert(sb2.str() == "testing"); + assert(is.good()); + assert(is.gcount() == 7); + assert(is.get() == '*'); + is.get(sb2, '*'); + assert(sb2.str() == "testing..."); + assert(is.eof()); + assert(!is.fail()); + assert(is.gcount() == 3); + } + { + testbuf<wchar_t> sb(L"testing*..."); + std::wistream is(&sb); + testbuf<wchar_t> sb2; + is.get(sb2, L'*'); + assert(sb2.str() == L"testing"); + assert(is.good()); + assert(is.gcount() == 7); + assert(is.get() == L'*'); + is.get(sb2, L'*'); + assert(sb2.str() == L"testing..."); + assert(is.eof()); + assert(!is.fail()); + assert(is.gcount() == 3); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp new file mode 100644 index 0000000000000..465824a659f28 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& getline(char_type* s, streamsize n); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" \n \n "); + std::istream is(&sb); + char s[5]; + is.getline(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 3); + is.getline(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 5); + is.getline(s, 5); + assert( is.eof()); + assert(!is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 1); + } + { + testbuf<wchar_t> sb(L" \n \n "); + std::wistream is(&sb); + wchar_t s[5]; + is.getline(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 3); + is.getline(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 5); + is.getline(s, 5); + assert( is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 1); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp new file mode 100644 index 0000000000000..7362959966a6d --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& getline(char_type* s, streamsize n, char_type delim); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" * * "); + std::istream is(&sb); + char s[5]; + is.getline(s, 5, '*'); + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 3); + is.getline(s, 5, '*'); + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 5); + is.getline(s, 5, '*'); + assert( is.eof()); + assert(!is.fail()); + assert(std::string(s) == " "); + assert(is.gcount() == 1); + } + { + testbuf<wchar_t> sb(L" * * "); + std::wistream is(&sb); + wchar_t s[5]; + is.getline(s, 5, L'*'); + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 3); + is.getline(s, 5, L'*'); + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 5); + is.getline(s, 5, L'*'); + assert( is.eof()); + assert(!is.fail()); + assert(std::wstring(s) == L" "); + assert(is.gcount() == 1); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.pass.cpp new file mode 100644 index 0000000000000..9510961a4c516 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& +// ignore(streamsize n = 1, int_type delim = traits::eof()); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" 1\n2345\n6"); + std::istream is(&sb); + is.ignore(); + assert(!is.eof()); + assert(!is.fail()); + assert(is.gcount() == 1); + is.ignore(5, '\n'); + assert(!is.eof()); + assert(!is.fail()); + assert(is.gcount() == 2); + is.ignore(15); + assert( is.eof()); + assert(!is.fail()); + assert(is.gcount() == 6); + } + { + testbuf<wchar_t> sb(L" 1\n2345\n6"); + std::wistream is(&sb); + is.ignore(); + assert(!is.eof()); + assert(!is.fail()); + assert(is.gcount() == 1); + is.ignore(5, '\n'); + assert(!is.eof()); + assert(!is.fail()); + assert(is.gcount() == 2); + is.ignore(15); + assert( is.eof()); + assert(!is.fail()); + assert(is.gcount() == 6); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp new file mode 100644 index 0000000000000..ccc3545483e71 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& +// ignore(streamsize n = 1, int_type delim = traits::eof()); + +// http://llvm.org/bugs/show_bug.cgi?id=16427 + +#include <sstream> +#include <cassert> + +int main() +{ + int bad=-1; + std::ostringstream os; + os << "aaaabbbb" << static_cast<char>(bad) + << "ccccdddd" << std::endl; + std::string s=os.str(); + + std::istringstream is(s); + const unsigned int ignoreLen=10; + size_t a=is.tellg(); + is.ignore(ignoreLen); + size_t b=is.tellg(); + assert((b-a)==ignoreLen); +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/peek.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/peek.pass.cpp new file mode 100644 index 0000000000000..4264849a09172 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/peek.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// int_type peek(); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" 1\n2345\n6"); + std::istream is(&sb); + assert(is.peek() == ' '); + assert(!is.eof()); + assert(!is.fail()); + assert(is.gcount() == 0); + is.get(); + assert(is.peek() == '1'); + assert(!is.eof()); + assert(!is.fail()); + assert(is.gcount() == 0); + } + { + testbuf<wchar_t> sb(L" 1\n2345\n6"); + std::wistream is(&sb); + assert(is.peek() == L' '); + assert(!is.eof()); + assert(!is.fail()); + assert(is.gcount() == 0); + is.get(); + assert(is.peek() == L'1'); + assert(!is.eof()); + assert(!is.fail()); + assert(is.gcount() == 0); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/putback.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/putback.pass.cpp new file mode 100644 index 0000000000000..3564d710bc238 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/putback.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& putback(char_type c); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" 123456789"); + std::istream is(&sb); + is.get(); + is.get(); + is.get(); + is.putback('a'); + assert(is.bad()); + assert(is.gcount() == 0); + is.clear(); + is.putback('2'); + assert(is.good()); + assert(is.gcount() == 0); + is.putback('1'); + assert(is.good()); + assert(is.gcount() == 0); + is.putback(' '); + assert(is.good()); + assert(is.gcount() == 0); + is.putback(' '); + assert(is.bad()); + assert(is.gcount() == 0); + } + { + testbuf<wchar_t> sb(L" 123456789"); + std::wistream is(&sb); + is.get(); + is.get(); + is.get(); + is.putback(L'a'); + assert(is.bad()); + assert(is.gcount() == 0); + is.clear(); + is.putback(L'2'); + assert(is.good()); + assert(is.gcount() == 0); + is.putback(L'1'); + assert(is.good()); + assert(is.gcount() == 0); + is.putback(L' '); + assert(is.good()); + assert(is.gcount() == 0); + is.putback(L' '); + assert(is.bad()); + assert(is.gcount() == 0); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/read.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/read.pass.cpp new file mode 100644 index 0000000000000..20e70cfbd5cdf --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/read.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& read(char_type* s, streamsize n); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" 123456789"); + std::istream is(&sb); + char s[5]; + is.read(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s, 5) == " 1234"); + assert(is.gcount() == 5); + is.read(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s, 5) == "56789"); + assert(is.gcount() == 5); + is.read(s, 5); + assert( is.eof()); + assert( is.fail()); + assert(is.gcount() == 0); + } + { + testbuf<wchar_t> sb(L" 123456789"); + std::wistream is(&sb); + wchar_t s[5]; + is.read(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s, 5) == L" 1234"); + assert(is.gcount() == 5); + is.read(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s, 5) == L"56789"); + assert(is.gcount() == 5); + is.read(s, 5); + assert( is.eof()); + assert( is.fail()); + assert(is.gcount() == 0); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/readsome.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/readsome.pass.cpp new file mode 100644 index 0000000000000..01eecb5d824ba --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/readsome.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// streamsize readsome(char_type* s, streamsize n); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" 1234567890"); + std::istream is(&sb); + char s[5]; + assert(is.readsome(s, 5) == 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s, 5) == " 1234"); + assert(is.gcount() == 5); + is.readsome(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::string(s, 5) == "56789"); + assert(is.gcount() == 5); + is.readsome(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(is.gcount() == 1); + assert(std::string(s, 1) == "0"); + assert(is.readsome(s, 5) == 0); + } + { + testbuf<wchar_t> sb(L" 1234567890"); + std::wistream is(&sb); + wchar_t s[5]; + assert(is.readsome(s, 5) == 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s, 5) == L" 1234"); + assert(is.gcount() == 5); + is.readsome(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(std::wstring(s, 5) == L"56789"); + assert(is.gcount() == 5); + is.readsome(s, 5); + assert(!is.eof()); + assert(!is.fail()); + assert(is.gcount() == 1); + assert(std::wstring(s, 1) == L"0"); + assert(is.readsome(s, 5) == 0); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/seekg.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/seekg.pass.cpp new file mode 100644 index 0000000000000..e6f4e1e4c19ec --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/seekg.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& seekg(pos_type pos); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +protected: + typename base::pos_type seekpos(typename base::pos_type sp, + std::ios_base::openmode which) + { + assert(which == std::ios_base::in); + return sp; + } +}; + +int main() +{ + { + testbuf<char> sb(" 123456789"); + std::istream is(&sb); + is.seekg(5); + assert(is.good()); + is.seekg(-1); + assert(is.fail()); + } + { + testbuf<wchar_t> sb(L" 123456789"); + std::wistream is(&sb); + is.seekg(5); + assert(is.good()); + is.seekg(-1); + assert(is.fail()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/seekg_off.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/seekg_off.pass.cpp new file mode 100644 index 0000000000000..73f3da1c6bd1f --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/seekg_off.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& seekg(off_type off, ios_base::seekdir dir); + +#include <istream> +#include <cassert> + +int seekoff_called = 0; + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +protected: + typename base::pos_type seekoff(typename base::off_type off, + std::ios_base::seekdir way, + std::ios_base::openmode which) + { + assert(which == std::ios_base::in); + ++seekoff_called; + return off; + } +}; + +int main() +{ + { + testbuf<char> sb(" 123456789"); + std::istream is(&sb); + is.seekg(5, std::ios_base::cur); + assert(is.good()); + assert(seekoff_called == 1); + is.seekg(-1, std::ios_base::beg); + assert(is.fail()); + assert(seekoff_called == 2); + } + { + testbuf<wchar_t> sb(L" 123456789"); + std::wistream is(&sb); + is.seekg(5, std::ios_base::cur); + assert(is.good()); + assert(seekoff_called == 3); + is.seekg(-1, std::ios_base::beg); + assert(is.fail()); + assert(seekoff_called == 4); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/sync.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/sync.pass.cpp new file mode 100644 index 0000000000000..61db67cd5a5d1 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/sync.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// int sync(); + +#include <istream> +#include <cassert> + +int sync_called = 0; + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} + +protected: + int sync() + { + ++sync_called; + return 5; + } +}; + +int main() +{ + { + testbuf<char> sb(" 123456789"); + std::istream is(&sb); + assert(is.sync() == 0); + assert(sync_called == 1); + } + { + testbuf<wchar_t> sb(L" 123456789"); + std::wistream is(&sb); + assert(is.sync() == 0); + assert(sync_called == 2); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/tellg.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/tellg.pass.cpp new file mode 100644 index 0000000000000..799b46b97dea8 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/tellg.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// pos_type tellg(); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +protected: + typename base::pos_type seekoff(typename base::off_type off, + std::ios_base::seekdir way, + std::ios_base::openmode which) + { + assert(off == 0); + assert(way == std::ios_base::cur); + assert(which == std::ios_base::in); + return 5; + } +}; + +int main() +{ + { + testbuf<char> sb(" 123456789"); + std::istream is(&sb); + assert(is.tellg() == 5); + } + { + testbuf<wchar_t> sb(L" 123456789"); + std::wistream is(&sb); + assert(is.tellg() == 5); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream.unformatted/unget.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream.unformatted/unget.pass.cpp new file mode 100644 index 0000000000000..adf0a6117c1de --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream.unformatted/unget.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// basic_istream<charT,traits>& unget(); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +}; + +int main() +{ + { + testbuf<char> sb(" 123456789"); + std::istream is(&sb); + is.get(); + is.get(); + is.get(); + is.unget(); + assert(is.good()); + assert(is.gcount() == 0); + is.unget(); + assert(is.good()); + assert(is.gcount() == 0); + is.unget(); + assert(is.good()); + assert(is.gcount() == 0); + is.unget(); + assert(is.bad()); + assert(is.gcount() == 0); + } + { + testbuf<wchar_t> sb(L" 123456789"); + std::wistream is(&sb); + is.get(); + is.get(); + is.get(); + is.unget(); + assert(is.good()); + assert(is.gcount() == 0); + is.unget(); + assert(is.good()); + assert(is.gcount() == 0); + is.unget(); + assert(is.good()); + assert(is.gcount() == 0); + is.unget(); + assert(is.bad()); + assert(is.gcount() == 0); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream/istream.assign/member_swap.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream/istream.assign/member_swap.pass.cpp new file mode 100644 index 0000000000000..a0734b8016b57 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream/istream.assign/member_swap.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// void swap(basic_istream& rhs); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +template <class CharT> +struct test_istream + : public std::basic_istream<CharT> +{ + typedef std::basic_istream<CharT> base; + test_istream(testbuf<CharT>* sb) : base(sb) {} + + void swap(test_istream& s) {base::swap(s);} +}; + +int main() +{ + { + testbuf<char> sb1; + testbuf<char> sb2; + test_istream<char> is1(&sb1); + test_istream<char> is2(&sb2); + is1.swap(is2); + assert(is1.rdbuf() == &sb1); + assert(is1.tie() == 0); + assert(is1.fill() == ' '); + assert(is1.rdstate() == is1.goodbit); + assert(is1.exceptions() == is1.goodbit); + assert(is1.flags() == (is1.skipws | is1.dec)); + assert(is1.precision() == 6); + assert(is1.getloc().name() == "C"); + assert(is2.rdbuf() == &sb2); + assert(is2.tie() == 0); + assert(is2.fill() == ' '); + assert(is2.rdstate() == is2.goodbit); + assert(is2.exceptions() == is2.goodbit); + assert(is2.flags() == (is2.skipws | is2.dec)); + assert(is2.precision() == 6); + assert(is2.getloc().name() == "C"); + } + { + testbuf<wchar_t> sb1; + testbuf<wchar_t> sb2; + test_istream<wchar_t> is1(&sb1); + test_istream<wchar_t> is2(&sb2); + is1.swap(is2); + assert(is1.rdbuf() == &sb1); + assert(is1.tie() == 0); + assert(is1.fill() == ' '); + assert(is1.rdstate() == is1.goodbit); + assert(is1.exceptions() == is1.goodbit); + assert(is1.flags() == (is1.skipws | is1.dec)); + assert(is1.precision() == 6); + assert(is1.getloc().name() == "C"); + assert(is2.rdbuf() == &sb2); + assert(is2.tie() == 0); + assert(is2.fill() == ' '); + assert(is2.rdstate() == is2.goodbit); + assert(is2.exceptions() == is2.goodbit); + assert(is2.flags() == (is2.skipws | is2.dec)); + assert(is2.precision() == 6); + assert(is2.getloc().name() == "C"); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream/istream.assign/move_assign.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream/istream.assign/move_assign.pass.cpp new file mode 100644 index 0000000000000..2876d76c19848 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream/istream.assign/move_assign.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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// basic_istream& operator=(basic_istream&& rhs); + +#include <istream> +#include <cassert> + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +template <class CharT> +struct test_istream + : public std::basic_istream<CharT> +{ + typedef std::basic_istream<CharT> base; + test_istream(testbuf<CharT>* sb) : base(sb) {} + + test_istream& operator=(test_istream&& s) + {base::operator=(std::move(s)); return *this;} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + testbuf<char> sb1; + testbuf<char> sb2; + test_istream<char> is1(&sb1); + test_istream<char> is2(&sb2); + is2 = (std::move(is1)); + assert(is1.rdbuf() == &sb1); + assert(is1.tie() == 0); + assert(is1.fill() == ' '); + assert(is1.rdstate() == is1.goodbit); + assert(is1.exceptions() == is1.goodbit); + assert(is1.flags() == (is1.skipws | is1.dec)); + assert(is1.precision() == 6); + assert(is1.getloc().name() == "C"); + assert(is2.rdbuf() == &sb2); + assert(is2.tie() == 0); + assert(is2.fill() == ' '); + assert(is2.rdstate() == is2.goodbit); + assert(is2.exceptions() == is2.goodbit); + assert(is2.flags() == (is2.skipws | is2.dec)); + assert(is2.precision() == 6); + assert(is2.getloc().name() == "C"); + } + { + testbuf<wchar_t> sb1; + testbuf<wchar_t> sb2; + test_istream<wchar_t> is1(&sb1); + test_istream<wchar_t> is2(&sb2); + is2 = (std::move(is1)); + assert(is1.rdbuf() == &sb1); + assert(is1.tie() == 0); + assert(is1.fill() == ' '); + assert(is1.rdstate() == is1.goodbit); + assert(is1.exceptions() == is1.goodbit); + assert(is1.flags() == (is1.skipws | is1.dec)); + assert(is1.precision() == 6); + assert(is1.getloc().name() == "C"); + assert(is2.rdbuf() == &sb2); + assert(is2.tie() == 0); + assert(is2.fill() == ' '); + assert(is2.rdstate() == is2.goodbit); + assert(is2.exceptions() == is2.goodbit); + assert(is2.flags() == (is2.skipws | is2.dec)); + assert(is2.precision() == 6); + assert(is2.getloc().name() == "C"); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/input.output/iostream.format/input.streams/istream/istream.cons/move.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream/istream.cons/move.pass.cpp new file mode 100644 index 0000000000000..04cb9d3fb6ba9 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream/istream.cons/move.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// basic_istream(basic_istream&& rhs); + +#include <istream> +#include <cassert> + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +template <class CharT> +struct test_istream + : public std::basic_istream<CharT> +{ + typedef std::basic_istream<CharT> base; + test_istream(testbuf<CharT>* sb) : base(sb) {} + + test_istream(test_istream&& s) + : base(std::move(s)) {} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + testbuf<char> sb; + test_istream<char> is1(&sb); + test_istream<char> is(std::move(is1)); + assert(is1.rdbuf() == &sb); + assert(is1.gcount() == 0); + assert(is.gcount() == 0); + assert(is.rdbuf() == 0); + assert(is.tie() == 0); + assert(is.fill() == ' '); + assert(is.rdstate() == is.goodbit); + assert(is.exceptions() == is.goodbit); + assert(is.flags() == (is.skipws | is.dec)); + assert(is.precision() == 6); + assert(is.getloc().name() == "C"); + } + { + testbuf<wchar_t> sb; + test_istream<wchar_t> is1(&sb); + test_istream<wchar_t> is(std::move(is1)); + assert(is1.gcount() == 0); + assert(is.gcount() == 0); + assert(is1.rdbuf() == &sb); + assert(is.rdbuf() == 0); + assert(is.tie() == 0); + assert(is.fill() == L' '); + assert(is.rdstate() == is.goodbit); + assert(is.exceptions() == is.goodbit); + assert(is.flags() == (is.skipws | is.dec)); + assert(is.precision() == 6); + assert(is.getloc().name() == "C"); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/input.output/iostream.format/input.streams/istream/istream.cons/streambuf.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream/istream.cons/streambuf.pass.cpp new file mode 100644 index 0000000000000..74ed57dae6bd3 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream/istream.cons/streambuf.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream; + +// explicit basic_istream(basic_streambuf<charT,traits>* sb); + +#include <istream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +int main() +{ + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + assert(is.rdbuf() == &sb); + assert(is.tie() == 0); + assert(is.fill() == ' '); + assert(is.rdstate() == is.goodbit); + assert(is.exceptions() == is.goodbit); + assert(is.flags() == (is.skipws | is.dec)); + assert(is.precision() == 6); + assert(is.getloc().name() == "C"); + assert(is.gcount() == 0); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + assert(is.rdbuf() == &sb); + assert(is.tie() == 0); + assert(is.fill() == L' '); + assert(is.rdstate() == is.goodbit); + assert(is.exceptions() == is.goodbit); + assert(is.flags() == (is.skipws | is.dec)); + assert(is.precision() == 6); + assert(is.getloc().name() == "C"); + assert(is.gcount() == 0); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream/istream_sentry/ctor.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream/istream_sentry/ctor.pass.cpp new file mode 100644 index 0000000000000..910b36931da32 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream/istream_sentry/ctor.pass.cpp @@ -0,0 +1,128 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream::sentry; + +// explicit sentry(basic_istream<charT,traits>& is, bool noskipws = false); + +#include <istream> +#include <cassert> + +int sync_called = 0; + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} +protected: + + int virtual sync() + { + ++sync_called; + return 1; + } +}; + +int main() +{ + { + std::istream is((testbuf<char>*)0); + std::istream::sentry sen(is, true); + assert(!(bool)sen); + assert(!is.good()); + assert(is.gcount() == 0); + assert(sync_called == 0); + } + { + std::wistream is((testbuf<wchar_t>*)0); + std::wistream::sentry sen(is, true); + assert(!(bool)sen); + assert(!is.good()); + assert(is.gcount() == 0); + assert(sync_called == 0); + } + { + testbuf<char> sb(" 123"); + std::istream is(&sb); + std::istream::sentry sen(is, true); + assert((bool)sen); + assert(is.good()); + assert(is.gcount() == 0); + assert(sync_called == 0); + assert(sb.gptr() == sb.eback()); + } + { + testbuf<wchar_t> sb(L" 123"); + std::wistream is(&sb); + std::wistream::sentry sen(is, true); + assert((bool)sen); + assert(is.good()); + assert(is.gcount() == 0); + assert(sync_called == 0); + assert(sb.gptr() == sb.eback()); + } + { + testbuf<char> sb(" 123"); + std::istream is(&sb); + std::istream::sentry sen(is); + assert((bool)sen); + assert(is.good()); + assert(sync_called == 0); + assert(sb.gptr() == sb.eback() + 3); + } + { + testbuf<wchar_t> sb(L" 123"); + std::wistream is(&sb); + std::wistream::sentry sen(is); + assert((bool)sen); + assert(is.good()); + assert(sync_called == 0); + assert(sb.gptr() == sb.eback() + 3); + } + { + testbuf<char> sb(" "); + std::istream is(&sb); + std::istream::sentry sen(is); + assert(!(bool)sen); + assert(is.fail()); + assert(is.eof()); + assert(sync_called == 0); + assert(sb.gptr() == sb.eback() + 6); + } + { + testbuf<char> sb(" "); + std::istream is(&sb); + std::istream::sentry sen(is, true); + assert((bool)sen); + assert(is.good()); + assert(sync_called == 0); + assert(sb.gptr() == sb.eback()); + } +} diff --git a/test/std/input.output/iostream.format/input.streams/istream/types.pass.cpp b/test/std/input.output/iostream.format/input.streams/istream/types.pass.cpp new file mode 100644 index 0000000000000..36cc2029db246 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/istream/types.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_istream +// : virtual public basic_ios<charT,traits> +// { +// public: +// // types (inherited from basic_ios (27.5.4)): +// typedef charT char_type; +// typedef traits traits_type; +// typedef typename traits_type::int_type int_type; +// typedef typename traits_type::pos_type pos_type; +// typedef typename traits_type::off_type off_type; + +#include <istream> +#include <type_traits> + +int main() +{ + static_assert((std::is_base_of<std::basic_ios<char>, std::basic_istream<char> >::value), ""); + static_assert((std::is_same<std::basic_istream<char>::char_type, char>::value), ""); + static_assert((std::is_same<std::basic_istream<char>::traits_type, std::char_traits<char> >::value), ""); + static_assert((std::is_same<std::basic_istream<char>::int_type, std::char_traits<char>::int_type>::value), ""); + static_assert((std::is_same<std::basic_istream<char>::pos_type, std::char_traits<char>::pos_type>::value), ""); + static_assert((std::is_same<std::basic_istream<char>::off_type, std::char_traits<char>::off_type>::value), ""); +} diff --git a/test/std/input.output/iostream.format/input.streams/version.pass.cpp b/test/std/input.output/iostream.format/input.streams/version.pass.cpp new file mode 100644 index 0000000000000..b03ef2aaa04e0 --- /dev/null +++ b/test/std/input.output/iostream.format/input.streams/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <istream> + +#include <istream> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/input.output/iostream.format/nothing_to_do.pass.cpp b/test/std/input.output/iostream.format/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/input.output/iostream.format/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.assign/member_swap.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.assign/member_swap.pass.cpp new file mode 100644 index 0000000000000..8214d6c05b5bf --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.assign/member_swap.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// void swap(basic_ostream& rhs); + +#include <ostream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +template <class CharT> +struct test_ostream + : public std::basic_ostream<CharT> +{ + typedef std::basic_ostream<CharT> base; + test_ostream(testbuf<CharT>* sb) : base(sb) {} + + void swap(test_ostream& s) {base::swap(s);} +}; + +int main() +{ + { + testbuf<char> sb1; + testbuf<char> sb2; + test_ostream<char> os1(&sb1); + test_ostream<char> os2(&sb2); + os1.swap(os2); + assert(os1.rdbuf() == &sb1); + assert(os1.tie() == 0); + assert(os1.fill() == ' '); + assert(os1.rdstate() == os1.goodbit); + assert(os1.exceptions() == os1.goodbit); + assert(os1.flags() == (os1.skipws | os1.dec)); + assert(os1.precision() == 6); + assert(os1.getloc().name() == "C"); + assert(os2.rdbuf() == &sb2); + assert(os2.tie() == 0); + assert(os2.fill() == ' '); + assert(os2.rdstate() == os2.goodbit); + assert(os2.exceptions() == os2.goodbit); + assert(os2.flags() == (os2.skipws | os2.dec)); + assert(os2.precision() == 6); + assert(os2.getloc().name() == "C"); + } + { + testbuf<wchar_t> sb1; + testbuf<wchar_t> sb2; + test_ostream<wchar_t> os1(&sb1); + test_ostream<wchar_t> os2(&sb2); + os1.swap(os2); + assert(os1.rdbuf() == &sb1); + assert(os1.tie() == 0); + assert(os1.fill() == ' '); + assert(os1.rdstate() == os1.goodbit); + assert(os1.exceptions() == os1.goodbit); + assert(os1.flags() == (os1.skipws | os1.dec)); + assert(os1.precision() == 6); + assert(os1.getloc().name() == "C"); + assert(os2.rdbuf() == &sb2); + assert(os2.tie() == 0); + assert(os2.fill() == ' '); + assert(os2.rdstate() == os2.goodbit); + assert(os2.exceptions() == os2.goodbit); + assert(os2.flags() == (os2.skipws | os2.dec)); + assert(os2.precision() == 6); + assert(os2.getloc().name() == "C"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.assign/move_assign.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.assign/move_assign.pass.cpp new file mode 100644 index 0000000000000..40fe0795de534 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.assign/move_assign.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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// basic_ostream& operator=(basic_ostream&& rhs); + +#include <ostream> +#include <cassert> + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +template <class CharT> +struct test_ostream + : public std::basic_ostream<CharT> +{ + typedef std::basic_ostream<CharT> base; + test_ostream(testbuf<CharT>* sb) : base(sb) {} + + test_ostream& operator=(test_ostream&& s) + {base::operator=(std::move(s)); return *this;} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + testbuf<char> sb1; + testbuf<char> sb2; + test_ostream<char> os1(&sb1); + test_ostream<char> os2(&sb2); + os2 = (std::move(os1)); + assert(os1.rdbuf() == &sb1); + assert(os1.tie() == 0); + assert(os1.fill() == ' '); + assert(os1.rdstate() == os1.goodbit); + assert(os1.exceptions() == os1.goodbit); + assert(os1.flags() == (os1.skipws | os1.dec)); + assert(os1.precision() == 6); + assert(os1.getloc().name() == "C"); + assert(os2.rdbuf() == &sb2); + assert(os2.tie() == 0); + assert(os2.fill() == ' '); + assert(os2.rdstate() == os2.goodbit); + assert(os2.exceptions() == os2.goodbit); + assert(os2.flags() == (os2.skipws | os2.dec)); + assert(os2.precision() == 6); + assert(os2.getloc().name() == "C"); + } + { + testbuf<wchar_t> sb1; + testbuf<wchar_t> sb2; + test_ostream<wchar_t> os1(&sb1); + test_ostream<wchar_t> os2(&sb2); + os2 = (std::move(os1)); + assert(os1.rdbuf() == &sb1); + assert(os1.tie() == 0); + assert(os1.fill() == ' '); + assert(os1.rdstate() == os1.goodbit); + assert(os1.exceptions() == os1.goodbit); + assert(os1.flags() == (os1.skipws | os1.dec)); + assert(os1.precision() == 6); + assert(os1.getloc().name() == "C"); + assert(os2.rdbuf() == &sb2); + assert(os2.tie() == 0); + assert(os2.fill() == ' '); + assert(os2.rdstate() == os2.goodbit); + assert(os2.exceptions() == os2.goodbit); + assert(os2.flags() == (os2.skipws | os2.dec)); + assert(os2.precision() == 6); + assert(os2.getloc().name() == "C"); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.cons/move.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.cons/move.pass.cpp new file mode 100644 index 0000000000000..b3045b3232e6e --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.cons/move.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// basic_ostream(basic_ostream&& rhs); + +#include <ostream> +#include <cassert> + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +template <class CharT> +struct test_ostream + : public std::basic_ostream<CharT> +{ + typedef std::basic_ostream<CharT> base; + test_ostream(testbuf<CharT>* sb) : base(sb) {} + + test_ostream(test_ostream&& s) + : base(std::move(s)) {} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + testbuf<char> sb; + test_ostream<char> os1(&sb); + test_ostream<char> os(std::move(os1)); + assert(os1.rdbuf() == &sb); + assert(os.rdbuf() == 0); + assert(os.tie() == 0); + assert(os.fill() == ' '); + assert(os.rdstate() == os.goodbit); + assert(os.exceptions() == os.goodbit); + assert(os.flags() == (os.skipws | os.dec)); + assert(os.precision() == 6); + assert(os.getloc().name() == "C"); + } + { + testbuf<wchar_t> sb; + test_ostream<wchar_t> os1(&sb); + test_ostream<wchar_t> os(std::move(os1)); + assert(os1.rdbuf() == &sb); + assert(os.rdbuf() == 0); + assert(os.tie() == 0); + assert(os.fill() == L' '); + assert(os.rdstate() == os.goodbit); + assert(os.exceptions() == os.goodbit); + assert(os.flags() == (os.skipws | os.dec)); + assert(os.precision() == 6); + assert(os.getloc().name() == "C"); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.cons/streambuf.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.cons/streambuf.pass.cpp new file mode 100644 index 0000000000000..7929e1845ec69 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.cons/streambuf.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// explicit basic_ostream(basic_streambuf<charT,traits>* sb); + +#include <ostream> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +int main() +{ + { + testbuf<char> sb; + std::basic_ostream<char> os(&sb); + assert(os.rdbuf() == &sb); + assert(os.tie() == 0); + assert(os.fill() == ' '); + assert(os.rdstate() == os.goodbit); + assert(os.exceptions() == os.goodbit); + assert(os.flags() == (os.skipws | os.dec)); + assert(os.precision() == 6); + assert(os.getloc().name() == "C"); + } + { + testbuf<wchar_t> sb; + std::basic_ostream<wchar_t> os(&sb); + assert(os.rdbuf() == &sb); + assert(os.tie() == 0); + assert(os.fill() == L' '); + assert(os.rdstate() == os.goodbit); + assert(os.exceptions() == os.goodbit); + assert(os.flags() == (os.skipws | os.dec)); + assert(os.precision() == 6); + assert(os.getloc().name() == "C"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/nothing_to_do.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.reqmts/tested_elsewhere.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.reqmts/tested_elsewhere.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.reqmts/tested_elsewhere.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/bool.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/bool.pass.cpp new file mode 100644 index 0000000000000..13035b74436e4 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/bool.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(bool val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + bool b = false; + os << b; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + bool b = false; + os << b; + assert(sb.str() == "0"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + bool b = true; + os << b; + assert(sb.str() == "1"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + boolalpha(os); + bool b = true; + os << b; + assert(sb.str() == "true"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + boolalpha(os); + bool b = false; + os << b; + assert(sb.str() == "false"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/double.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/double.pass.cpp new file mode 100644 index 0000000000000..38ee37ff18923 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/double.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(double val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + double n = 0; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + double n = 0; + os << n; + assert(sb.str() == "0"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + double n = -10; + os << n; + assert(sb.str() == "-10"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + hex(os); + double n = -10.5; + os << n; + assert(sb.str() == "-10.5"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/float.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/float.pass.cpp new file mode 100644 index 0000000000000..1da0ac685fcbd --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/float.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(float val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + float n = 0; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + float n = 0; + os << n; + assert(sb.str() == "0"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + float n = -10; + os << n; + assert(sb.str() == "-10"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + hex(os); + float n = -10.5; + os << n; + assert(sb.str() == "-10.5"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/int.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/int.pass.cpp new file mode 100644 index 0000000000000..efcb08a3da10a --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/int.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(int val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + int n = 0; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + int n = 0; + os << n; + assert(sb.str() == "0"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + int n = -10; + os << n; + assert(sb.str() == "-10"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + hex(os); + int n = -10; + os << n; + assert(sb.str() == "fffffff6"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long.pass.cpp new file mode 100644 index 0000000000000..6d617a453ebcd --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(long val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + long n = 0; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + long n = 0; + os << n; + assert(sb.str() == "0"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + long n = -10; + os << n; + assert(sb.str() == "-10"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + hex(os); + long n = 0xfffffff6; + os << n; + assert(sb.str() == "fffffff6"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long_double.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long_double.pass.cpp new file mode 100644 index 0000000000000..20b20b2231a2b --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long_double.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(long double val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + long double n = 0; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + long double n = 0; + os << n; + assert(sb.str() == "0"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + long double n = -10; + os << n; + assert(sb.str() == "-10"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + hex(os); + long double n = -10.5; + os << n; + assert(sb.str() == "-10.5"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long_long.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long_long.pass.cpp new file mode 100644 index 0000000000000..dc77eb72192d1 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long_long.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(long long val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + long long n = 0; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + long long n = 0; + os << n; + assert(sb.str() == "0"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + long long n = -10; + os << n; + assert(sb.str() == "-10"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + hex(os); + long long n = -10; + os << n; + assert(sb.str() == "fffffffffffffff6"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass new file mode 100644 index 0000000000000..27b8cfd85c960 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<( int16_t val); +// operator<<(uint16_t val); +// operator<<( int32_t val); +// operator<<(uint32_t val); +// operator<<( int64_t val); +// operator<<(uint64_t val); + +// Testing to make sure that the max length values are correctly inserted + +#include <iostream> +#include <sstream> +#include <cassert> + +template <typename T> +void test_octal(const char *expected) +{ + std::stringstream ss; + ss << std::oct << static_cast<T>(-1); + + assert(ss.str() == expected); +} + +template <typename T> +void test_dec(const char *expected) +{ + std::stringstream ss; + ss << std::dec << static_cast<T>(-1); + +// std::cout << ss.str() << " " << expected << std::endl; + assert(ss.str() == expected); +} + +template <typename T> +void test_hex(const char *expected) +{ + std::stringstream ss; + ss << std::hex << static_cast<T>(-1); + + std::string str = ss.str(); + for (size_t i = 0; i < str.size(); ++i ) + str[i] = std::toupper(str[i]); + + assert(str == expected); +} + +int main(int argc, char* argv[]) +{ + test_octal<uint16_t>( "177777"); + test_octal< int16_t>( "177777"); + test_octal<uint32_t>( "37777777777"); + test_octal< int32_t>( "37777777777"); + test_octal<uint64_t>("1777777777777777777777"); + test_octal< int64_t>("1777777777777777777777"); + + test_dec<uint16_t>( "65535"); + test_dec< int16_t>( "-1"); + test_dec<uint32_t>( "4294967295"); + test_dec< int32_t>( "-1"); + test_dec<uint64_t>("18446744073709551615"); + test_dec< int64_t>( "-1"); + + test_hex<uint16_t>( "FFFF"); + test_hex< int16_t>( "FFFF"); + test_hex<uint32_t>( "FFFFFFFF"); + test_hex< int32_t>( "FFFFFFFF"); + test_hex<uint64_t>("FFFFFFFFFFFFFFFF"); + test_hex< int64_t>("FFFFFFFFFFFFFFFF"); + + return 0; +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/pointer.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/pointer.pass.cpp new file mode 100644 index 0000000000000..b74d99a34ec97 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/pointer.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(const void* val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + const void* n = 0; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb1; + std::ostream os1(&sb1); + int n1; + os1 << &n1; + assert(os1.good()); + std::string s1(sb1.str()); + + testbuf<char> sb2; + std::ostream os2(&sb2); + int n2; + os2 << &n2; + assert(os2.good()); + std::string s2(sb2.str()); + + // %p is implementation defined. Instead of validating the + // output, at least ensure that it does not generate an empty + // string. Also make sure that given two distinct addresses, the + // output of %p is different. + assert(!s1.empty()); + assert(!s2.empty()); + assert(s1 != s2); + } + { + testbuf<char> sb; + std::ostream os(&sb); + const void* n = &sb; + os << n; + assert(os.good()); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/short.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/short.pass.cpp new file mode 100644 index 0000000000000..ebd349bcbb79c --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/short.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(short val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + short n = 0; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + short n = 0; + os << n; + assert(sb.str() == "0"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + short n = -10; + os << n; + assert(sb.str() == "-10"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + hex(os); + short n = -10; + os << n; + assert(sb.str() == "fff6"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_int.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_int.pass.cpp new file mode 100644 index 0000000000000..ac60fa9c19792 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_int.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(unsigned int val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + unsigned int n = 0; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + unsigned int n = 0; + os << n; + assert(sb.str() == "0"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + unsigned int n = 10; + os << n; + assert(sb.str() == "10"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + hex(os); + unsigned int n = 0xFFF6; + os << n; + assert(sb.str() == "fff6"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_long.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_long.pass.cpp new file mode 100644 index 0000000000000..b5a38017dce4b --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_long.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(unsigned long val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + unsigned long n = 0; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + unsigned long n = 0; + os << n; + assert(sb.str() == "0"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + unsigned long n = 10; + os << n; + assert(sb.str() == "10"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + hex(os); + unsigned long n = 0xfffffff6; + os << n; + assert(sb.str() == "fffffff6"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_long_long.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_long_long.pass.cpp new file mode 100644 index 0000000000000..25dc4d8349753 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_long_long.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(unsigned long long val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + unsigned long long n = 0; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + unsigned long long n = 0; + os << n; + assert(sb.str() == "0"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + unsigned long long n = 10; + os << n; + assert(sb.str() == "10"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + hex(os); + unsigned long long n = -10; + os << n; + assert(sb.str() == "fffffffffffffff6"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_short.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_short.pass.cpp new file mode 100644 index 0000000000000..7c28a8ee79c4a --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_short.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(unsigned short val); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + unsigned short n = 0; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + unsigned short n = 0; + os << n; + assert(sb.str() == "0"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + unsigned short n = 10; + os << n; + assert(sb.str() == "10"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + hex(os); + unsigned short n = 0xFFF6; + os << n; + assert(sb.str() == "fff6"); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/CharT.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/CharT.pass.cpp new file mode 100644 index 0000000000000..f74e2a4abd9ef --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/CharT.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template<class charT, class traits> +// basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, charT c); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::wostream os((std::wstreambuf*)0); + wchar_t c = L'a'; + os << c; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + wchar_t c = L'a'; + os << c; + assert(sb.str() == L"a"); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.width(5); + wchar_t c = L'a'; + os << c; + assert(sb.str() == L" a"); + assert(os.width() == 0); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.width(5); + left(os); + wchar_t c = L'a'; + os << c; + assert(sb.str() == L"a "); + assert(os.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/CharT_pointer.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/CharT_pointer.pass.cpp new file mode 100644 index 0000000000000..2b78fa75aa305 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/CharT_pointer.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template<class charT, class traits> +// basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, const charT* s); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::wostream os((std::wstreambuf*)0); + const wchar_t* c = L"123"; + os << c; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + const wchar_t* c = L"123"; + os << c; + assert(sb.str() == L"123"); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.width(5); + const wchar_t* c = L"123"; + os << c; + assert(sb.str() == L" 123"); + assert(os.width() == 0); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.width(5); + left(os); + const wchar_t* c = L"123"; + os << c; + assert(sb.str() == L"123 "); + assert(os.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char.pass.cpp new file mode 100644 index 0000000000000..253b524308c0f --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template<class char, class traits> +// basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out, char c); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + char c = 'a'; + os << c; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + char c = 'a'; + os << c; + assert(sb.str() == "a"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.width(5); + char c = 'a'; + os << c; + assert(sb.str() == " a"); + assert(os.width() == 0); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.width(5); + left(os); + char c = 'a'; + os << c; + assert(sb.str() == "a "); + assert(os.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_pointer.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_pointer.pass.cpp new file mode 100644 index 0000000000000..c544554ae0e20 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_pointer.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template<class traits> +// basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out, const char* s); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + const char* c = "123"; + os << c; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + const char* c = "123"; + os << c; + assert(sb.str() == "123"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.width(5); + const char* c = "123"; + os << c; + assert(sb.str() == " 123"); + assert(os.width() == 0); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.width(5); + left(os); + const char* c = "123"; + os << c; + assert(sb.str() == "123 "); + assert(os.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_to_wide.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_to_wide.pass.cpp new file mode 100644 index 0000000000000..6449a13a6426f --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_to_wide.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template<class charT, class traits> +// basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, char c); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::wostream os((std::wstreambuf*)0); + char c = 'a'; + os << c; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + char c = 'a'; + os << c; + assert(sb.str() == L"a"); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.width(5); + char c = 'a'; + os << c; + assert(sb.str() == L" a"); + assert(os.width() == 0); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.width(5); + left(os); + char c = 'a'; + os << c; + assert(sb.str() == L"a "); + assert(os.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_to_wide_pointer.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_to_wide_pointer.pass.cpp new file mode 100644 index 0000000000000..e679a5c48ba4d --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_to_wide_pointer.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template<class charT, class traits> +// basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, const char* s); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::wostream os((std::wstreambuf*)0); + const char* c = "123"; + os << c; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + const char* c = "123"; + os << c; + assert(sb.str() == L"123"); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.width(5); + const char* c = "123"; + os << c; + assert(sb.str() == L" 123"); + assert(os.width() == 0); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.width(5); + left(os); + const char* c = "123"; + os << c; + assert(sb.str() == L"123 "); + assert(os.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/signed_char.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/signed_char.pass.cpp new file mode 100644 index 0000000000000..dc0ee4266c775 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/signed_char.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template<class char, class traits> +// basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out, signed char c); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + signed char c = 'a'; + os << c; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + signed char c = 'a'; + os << c; + assert(sb.str() == "a"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.width(5); + signed char c = 'a'; + os << c; + assert(sb.str() == " a"); + assert(os.width() == 0); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.width(5); + left(os); + signed char c = 'a'; + os << c; + assert(sb.str() == "a "); + assert(os.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/signed_char_pointer.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/signed_char_pointer.pass.cpp new file mode 100644 index 0000000000000..e465b94b6b93c --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/signed_char_pointer.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template<class traits> +// basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out, const signed char* s); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + const signed char* c = (const signed char*)"123"; + os << c; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + const signed char* c = (const signed char*)"123"; + os << c; + assert(sb.str() == "123"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.width(5); + const signed char* c = (const signed char*)"123"; + os << c; + assert(sb.str() == " 123"); + assert(os.width() == 0); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.width(5); + left(os); + const signed char* c = (const signed char*)"123"; + os << c; + assert(sb.str() == "123 "); + assert(os.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/unsigned_char.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/unsigned_char.pass.cpp new file mode 100644 index 0000000000000..d818c5f358f2e --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/unsigned_char.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template<class char, class traits> +// basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out, unsigned char c); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + unsigned char c = 'a'; + os << c; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + unsigned char c = 'a'; + os << c; + assert(sb.str() == "a"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.width(5); + unsigned char c = 'a'; + os << c; + assert(sb.str() == " a"); + assert(os.width() == 0); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.width(5); + left(os); + unsigned char c = 'a'; + os << c; + assert(sb.str() == "a "); + assert(os.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/unsigned_char_pointer.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/unsigned_char_pointer.pass.cpp new file mode 100644 index 0000000000000..3257f4a776ca8 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/unsigned_char_pointer.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template<class traits> +// basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out, const unsigned char* s); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + const unsigned char* c = (const unsigned char*)"123"; + os << c; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + const unsigned char* c = (const unsigned char*)"123"; + os << c; + assert(sb.str() == "123"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.width(5); + const unsigned char* c = (const unsigned char*)"123"; + os << c; + assert(sb.str() == " 123"); + assert(os.width() == 0); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.width(5); + left(os); + const unsigned char* c = (const unsigned char*)"123"; + os << c; + assert(sb.str() == "123 "); + assert(os.width() == 0); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/basic_ios.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/basic_ios.pass.cpp new file mode 100644 index 0000000000000..e26466e13f6e7 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/basic_ios.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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// basic_ostream<charT,traits>& operator<<(basic_ios<charT,traits>& +// (*pf)(basic_ios<charT,traits>&)); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +template <class CharT> +std::basic_ios<CharT>& +f(std::basic_ios<CharT>& os) +{ + std::uppercase(os); + return os; +} + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + assert(!(os.flags() & std::ios_base::uppercase)); + os << f; + assert( (os.flags() & std::ios_base::uppercase)); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/ios_base.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/ios_base.pass.cpp new file mode 100644 index 0000000000000..238a621082495 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/ios_base.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// basic_ostream<charT,traits>& operator<<(ios_base& (*pf)(ios_base&)); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + assert(!(os.flags() & std::ios_base::uppercase)); + os << std::uppercase; + assert( (os.flags() & std::ios_base::uppercase)); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/ostream.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/ostream.pass.cpp new file mode 100644 index 0000000000000..3ed400a705caa --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/ostream.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// basic_ostream<charT,traits>& operator<< +// (basic_ostream<charT,traits>& (*pf)(basic_ostream<charT,traits>&)) + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +template <class CharT> +std::basic_ostream<CharT>& +f(std::basic_ostream<CharT>& os) +{ + os << "testing..."; + return os; +} + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + os << f; + assert(sb.str() == "testing..."); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp new file mode 100644 index 0000000000000..1cb9413a7cc92 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// basic_ostream<charT,traits>& operator<<(basic_streambuf<charT,traits>* sb); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + testbuf(const std::basic_string<CharT>& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + testbuf<char> sb2("testing..."); + assert(sb.str() == ""); + os << &sb2; + assert(sb.str() == "testing..."); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.manip/endl.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.manip/endl.pass.cpp new file mode 100644 index 0000000000000..d503544a97f22 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.manip/endl.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template <class charT, class traits> +// basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os); + +#include <ostream> +#include <cassert> + +int sync_called = 0; + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } + + virtual int + sync() + { + ++sync_called; + return 0; + } +}; + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + endl(os); + assert(sb.str() == "\n"); + assert(sync_called == 1); + assert(os.good()); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + endl(os); + assert(sb.str() == L"\n"); + assert(sync_called == 2); + assert(os.good()); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.manip/ends.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.manip/ends.pass.cpp new file mode 100644 index 0000000000000..975b660b4770b --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.manip/ends.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template <class charT, class traits> +// basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + ends(os); + assert(sb.str().size() == 1); + assert(sb.str().back() == 0); + assert(os.good()); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + ends(os); + assert(sb.str().size() == 1); + assert(sb.str().back() == 0); + assert(os.good()); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.manip/flush.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.manip/flush.pass.cpp new file mode 100644 index 0000000000000..088826c3d5a93 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.manip/flush.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template <class charT, class traits> +// basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os); + +#include <ostream> +#include <cassert> + +int sync_called = 0; + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ +public: + testbuf() + { + } + +protected: + + virtual int + sync() + { + ++sync_called; + return 0; + } +}; + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + flush(os); + assert(sync_called == 1); + assert(os.good()); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + flush(os); + assert(sync_called == 2); + assert(os.good()); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.rvalue/CharT_pointer.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.rvalue/CharT_pointer.pass.cpp new file mode 100644 index 0000000000000..ec0e8e1e8c7a6 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.rvalue/CharT_pointer.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// template <class charT, class traits, class T> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>&& os, const T& x); + +#include <ostream> +#include <cassert> + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + testbuf<char> sb; + std::ostream(&sb) << "testing..."; + assert(sb.str() == "testing..."); + } + { + testbuf<wchar_t> sb; + std::wostream(&sb) << L"123"; + assert(sb.str() == L"123"); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp.pass.cpp new file mode 100644 index 0000000000000..ec3fe48866c77 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// basic_ostream<charT,traits>& seekp(pos_type pos); + +#include <ostream> +#include <cassert> + +int seekpos_called = 0; + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + testbuf() {} + +protected: + + typename base::pos_type + seekpos(typename base::pos_type sp, std::ios_base::openmode which) + { + ++seekpos_called; + assert(which == std::ios_base::out); + return sp; + } +}; + +int main() +{ + { + seekpos_called = 0; + std::ostream os((std::streambuf*)0); + assert(&os.seekp(5) == &os); + assert(seekpos_called == 0); + } + { + seekpos_called = 0; + testbuf<char> sb; + std::ostream os(&sb); + assert(&os.seekp(10) == &os); + assert(seekpos_called == 1); + assert(os.good()); + assert(&os.seekp(-1) == &os); + assert(seekpos_called == 2); + assert(os.fail()); + } + { // See https://llvm.org/bugs/show_bug.cgi?id=21361 + seekpos_called = 0; + testbuf<char> sb; + std::ostream os(&sb); + os.setstate(std::ios_base::eofbit); + assert(&os.seekp(10) == &os); + assert(seekpos_called == 1); + assert(os.rdstate() == std::ios_base::eofbit); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp2.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp2.pass.cpp new file mode 100644 index 0000000000000..ebfd24af91d5b --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp2.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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// basic_ostream<charT,traits>& seekp(off_type off, ios_base::seekdir dir); + +#include <ostream> +#include <cassert> + +int seekoff_called = 0; + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + testbuf() {} + +protected: + + typename base::pos_type + seekoff(typename base::off_type off, std::ios_base::seekdir way, + std::ios_base::openmode which) + { + ++seekoff_called; + assert(way == std::ios_base::beg); + assert(which == std::ios_base::out); + return off; + } +}; + +int main() +{ + { + seekoff_called = 0; + std::ostream os((std::streambuf*)0); + assert(&os.seekp(5, std::ios_base::beg) == &os); + assert(seekoff_called == 0); + } + { + seekoff_called = 0; + testbuf<char> sb; + std::ostream os(&sb); + assert(&os.seekp(10, std::ios_base::beg) == &os); + assert(seekoff_called == 1); + assert(os.good()); + assert(&os.seekp(-1, std::ios_base::beg) == &os); + assert(seekoff_called == 2); + assert(os.fail()); + } + { // See https://llvm.org/bugs/show_bug.cgi?id=21361 + seekoff_called = 0; + testbuf<char> sb; + std::ostream os(&sb); + os.setstate(std::ios_base::eofbit); + assert(&os.seekp(10, std::ios_base::beg) == &os); + assert(seekoff_called == 1); + assert(os.rdstate() == std::ios_base::eofbit); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.seeks/tellp.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.seeks/tellp.pass.cpp new file mode 100644 index 0000000000000..10a229d382b04 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.seeks/tellp.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// pos_type tellp(); + +#include <ostream> +#include <cassert> + +int seekoff_called = 0; + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + testbuf() {} + +protected: + + typename base::pos_type + seekoff(typename base::off_type off, std::ios_base::seekdir way, std::ios_base::openmode which) + { + assert(off == 0); + assert(way == std::ios_base::cur); + assert(which == std::ios_base::out); + ++seekoff_called; + return 10; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + assert(os.tellp() == -1); + } + { + testbuf<char> sb; + std::ostream os(&sb); + assert(os.tellp() == 10); + assert(seekoff_called == 1); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.unformatted/flush.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.unformatted/flush.pass.cpp new file mode 100644 index 0000000000000..97791f4c7a9cc --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.unformatted/flush.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// basic_ostream& flush(); + +#include <ostream> +#include <cassert> + +int sync_called = 0; + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ +public: + testbuf() + { + } + +protected: + + virtual int + sync() + { + if (sync_called++ == 1) + return -1; + return 0; + } +}; + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + os.flush(); + assert(os.good()); + assert(sync_called == 1); + os.flush(); + assert(os.bad()); + assert(sync_called == 2); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.unformatted/put.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.unformatted/put.pass.cpp new file mode 100644 index 0000000000000..396bb093f9c7e --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.unformatted/put.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// basic_ostream<charT,traits>& put(char_type c); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::wostream os((std::wstreambuf*)0); + wchar_t c = L'a'; + os.put(c); + assert(os.bad()); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + wchar_t c = L'a'; + os.put(c); + assert(sb.str() == L"a"); + assert(os.good()); + } + { + testbuf<char> sb; + std::ostream os(&sb); + char c = 'a'; + os.put(c); + assert(sb.str() == "a"); + assert(os.good()); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream.unformatted/write.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream.unformatted/write.pass.cpp new file mode 100644 index 0000000000000..8dd4e4cf76a6d --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream.unformatted/write.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// basic_ostream& write(const char_type* s, streamsize n); + +#include <ostream> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::wostream os((std::wstreambuf*)0); + const wchar_t s[] = L"123456790"; + os.write(s, sizeof(s)/sizeof(s[0])-1); + assert(os.bad()); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + const wchar_t s[] = L"123456790"; + os.write(s, sizeof(s)/sizeof(s[0])-1); + assert(os.good()); + assert(sb.str() == s); + } + { + testbuf<char> sb; + std::ostream os(&sb); + const char s[] = "123456790"; + os.write(s, sizeof(s)/sizeof(s[0])-1); + assert(sb.str() == s); + assert(os.good()); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream/types.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream/types.pass.cpp new file mode 100644 index 0000000000000..41ce0346c48bc --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream/types.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream +// : virtual public basic_ios<charT,traits> +// { +// public: +// // types (inherited from basic_ios (27.5.4)): +// typedef charT char_type; +// typedef traits traits_type; +// typedef typename traits_type::int_type int_type; +// typedef typename traits_type::pos_type pos_type; +// typedef typename traits_type::off_type off_type; + +#include <ostream> +#include <type_traits> + +int main() +{ + static_assert((std::is_base_of<std::basic_ios<char>, std::basic_ostream<char> >::value), ""); + static_assert((std::is_same<std::basic_ostream<char>::char_type, char>::value), ""); + static_assert((std::is_same<std::basic_ostream<char>::traits_type, std::char_traits<char> >::value), ""); + static_assert((std::is_same<std::basic_ostream<char>::int_type, std::char_traits<char>::int_type>::value), ""); + static_assert((std::is_same<std::basic_ostream<char>::pos_type, std::char_traits<char>::pos_type>::value), ""); + static_assert((std::is_same<std::basic_ostream<char>::off_type, std::char_traits<char>::off_type>::value), ""); +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream_sentry/construct.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream_sentry/construct.pass.cpp new file mode 100644 index 0000000000000..991fdfb357220 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream_sentry/construct.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream::sentry; + +// explicit sentry(basic_ostream<charT,traits>& os); + +#include <ostream> +#include <cassert> + +int sync_called = 0; + +template <class CharT> +struct testbuf1 + : public std::basic_streambuf<CharT> +{ + testbuf1() {} + +protected: + + int virtual sync() + { + ++sync_called; + return 1; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + std::ostream::sentry s(os); + assert(!bool(s)); + } + { + testbuf1<char> sb; + std::ostream os(&sb); + std::ostream::sentry s(os); + assert(bool(s)); + } + { + testbuf1<char> sb; + std::ostream os(&sb); + testbuf1<char> sb2; + std::ostream os2(&sb2); + os.tie(&os2); + assert(sync_called == 0); + std::ostream::sentry s(os); + assert(bool(s)); + assert(sync_called == 1); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/ostream_sentry/destruct.pass.cpp b/test/std/input.output/iostream.format/output.streams/ostream_sentry/destruct.pass.cpp new file mode 100644 index 0000000000000..112928ca0ce68 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/ostream_sentry/destruct.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream::sentry; + +// ~sentry(); + +#include <ostream> +#include <cassert> + +int sync_called = 0; + +template <class CharT> +struct testbuf1 + : public std::basic_streambuf<CharT> +{ + testbuf1() {} + +protected: + + int virtual sync() + { + ++sync_called; + return 1; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + std::ostream::sentry s(os); + assert(!bool(s)); + } + assert(sync_called == 0); + { + testbuf1<char> sb; + std::ostream os(&sb); + std::ostream::sentry s(os); + assert(bool(s)); + } + assert(sync_called == 0); + { + testbuf1<char> sb; + std::ostream os(&sb); + std::ostream::sentry s(os); + assert(bool(s)); + unitbuf(os); + } + assert(sync_called == 1); + { + testbuf1<char> sb; + std::ostream os(&sb); + try + { + std::ostream::sentry s(os); + assert(bool(s)); + unitbuf(os); + throw 1; + } + catch (...) + { + } + assert(sync_called == 1); + } +} diff --git a/test/std/input.output/iostream.format/output.streams/version.pass.cpp b/test/std/input.output/iostream.format/output.streams/version.pass.cpp new file mode 100644 index 0000000000000..662b6987b3c81 --- /dev/null +++ b/test/std/input.output/iostream.format/output.streams/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +#include <ostream> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/input.output/iostream.format/quoted.manip/quoted.pass.cpp b/test/std/input.output/iostream.format/quoted.manip/quoted.pass.cpp new file mode 100644 index 0000000000000..d09b3cae4f66e --- /dev/null +++ b/test/std/input.output/iostream.format/quoted.manip/quoted.pass.cpp @@ -0,0 +1,219 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// quoted + +#include <iomanip> +#include <sstream> +#include <string> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +bool is_skipws ( const std::istream *is ) { + return ( is->flags() & std::ios_base::skipws ) != 0; + } + + +bool is_skipws ( const std::wistream *is ) { + return ( is->flags() & std::ios_base::skipws ) != 0; + } + +void both_ways ( const char *p ) { + std::string str(p); + auto q = std::quoted(str); + + std::stringstream ss; + bool skippingws = is_skipws ( &ss ); + ss << q; + ss >> q; + } + +void round_trip ( const char *p ) { + std::stringstream ss; + bool skippingws = is_skipws ( &ss ); + ss << std::quoted(p); + std::string s; + ss >> std::quoted(s); + assert ( s == p ); + assert ( skippingws == is_skipws ( &ss )); + } + +void round_trip_ws ( const char *p ) { + std::stringstream ss; + std::noskipws ( ss ); + bool skippingws = is_skipws ( &ss ); + ss << std::quoted(p); + std::string s; + ss >> std::quoted(s); + assert ( s == p ); + assert ( skippingws == is_skipws ( &ss )); + } + +void round_trip_d ( const char *p, char delim ) { + std::stringstream ss; + ss << std::quoted(p, delim); + std::string s; + ss >> std::quoted(s, delim); + assert ( s == p ); + } + +void round_trip_e ( const char *p, char escape ) { + std::stringstream ss; + ss << std::quoted(p, '"', escape ); + std::string s; + ss >> std::quoted(s, '"', escape ); + assert ( s == p ); + } + + + +std::string quote ( const char *p, char delim='"', char escape='\\' ) { + std::stringstream ss; + ss << std::quoted(p, delim, escape); + std::string s; + ss >> s; // no quote + return s; +} + +std::string unquote ( const char *p, char delim='"', char escape='\\' ) { + std::stringstream ss; + ss << p; + std::string s; + ss >> std::quoted(s, delim, escape); + return s; +} + +void test_padding () { + { + std::stringstream ss; + ss << std::left << std::setw(10) << std::setfill('!') << std::quoted("abc", '`'); + assert ( ss.str() == "`abc`!!!!!" ); + } + + { + std::stringstream ss; + ss << std::right << std::setw(10) << std::setfill('!') << std::quoted("abc", '`'); + assert ( ss.str() == "!!!!!`abc`" ); + } +} + + +void round_trip ( const wchar_t *p ) { + std::wstringstream ss; + bool skippingws = is_skipws ( &ss ); + ss << std::quoted(p); + std::wstring s; + ss >> std::quoted(s); + assert ( s == p ); + assert ( skippingws == is_skipws ( &ss )); + } + + +void round_trip_ws ( const wchar_t *p ) { + std::wstringstream ss; + std::noskipws ( ss ); + bool skippingws = is_skipws ( &ss ); + ss << std::quoted(p); + std::wstring s; + ss >> std::quoted(s); + assert ( s == p ); + assert ( skippingws == is_skipws ( &ss )); + } + +void round_trip_d ( const wchar_t *p, wchar_t delim ) { + std::wstringstream ss; + ss << std::quoted(p, delim); + std::wstring s; + ss >> std::quoted(s, delim); + assert ( s == p ); + } + +void round_trip_e ( const wchar_t *p, wchar_t escape ) { + std::wstringstream ss; + ss << std::quoted(p, wchar_t('"'), escape ); + std::wstring s; + ss >> std::quoted(s, wchar_t('"'), escape ); + assert ( s == p ); + } + + +std::wstring quote ( const wchar_t *p, wchar_t delim='"', wchar_t escape='\\' ) { + std::wstringstream ss; + ss << std::quoted(p, delim, escape); + std::wstring s; + ss >> s; // no quote + return s; +} + +std::wstring unquote ( const wchar_t *p, wchar_t delim='"', wchar_t escape='\\' ) { + std::wstringstream ss; + ss << p; + std::wstring s; + ss >> std::quoted(s, delim, escape); + return s; +} + +int main() +{ + both_ways ( "" ); // This is a compilation check + + round_trip ( "" ); + round_trip_ws ( "" ); + round_trip_d ( "", 'q' ); + round_trip_e ( "", 'q' ); + + round_trip ( L"" ); + round_trip_ws ( L"" ); + round_trip_d ( L"", 'q' ); + round_trip_e ( L"", 'q' ); + + round_trip ( "Hi" ); + round_trip_ws ( "Hi" ); + round_trip_d ( "Hi", '!' ); + round_trip_e ( "Hi", '!' ); + assert ( quote ( "Hi", '!' ) == "!Hi!" ); + assert ( quote ( "Hi!", '!' ) == R"(!Hi\!!)" ); + + round_trip ( L"Hi" ); + round_trip_ws ( L"Hi" ); + round_trip_d ( L"Hi", '!' ); + round_trip_e ( L"Hi", '!' ); + assert ( quote ( L"Hi", '!' ) == L"!Hi!" ); + assert ( quote ( L"Hi!", '!' ) == LR"(!Hi\!!)" ); + + round_trip ( "Hi Mom" ); + round_trip_ws ( "Hi Mom" ); + round_trip ( L"Hi Mom" ); + round_trip_ws ( L"Hi Mom" ); + + assert ( quote ( "" ) == "\"\"" ); + assert ( quote ( L"" ) == L"\"\"" ); + assert ( quote ( "a" ) == "\"a\"" ); + assert ( quote ( L"a" ) == L"\"a\"" ); + +// missing end quote - must not hang + assert ( unquote ( "\"abc" ) == "abc" ); + assert ( unquote ( L"\"abc" ) == L"abc" ); + + assert ( unquote ( "abc" ) == "abc" ); // no delimiter + assert ( unquote ( L"abc" ) == L"abc" ); // no delimiter + assert ( unquote ( "abc def" ) == "abc" ); // no delimiter + assert ( unquote ( L"abc def" ) == L"abc" ); // no delimiter + + assert ( unquote ( "" ) == "" ); // nothing there + assert ( unquote ( L"" ) == L"" ); // nothing there + test_padding (); + } + +#else +int main() {} +#endif diff --git a/test/std/input.output/iostream.format/quoted.manip/quoted_char.fail.cpp b/test/std/input.output/iostream.format/quoted.manip/quoted_char.fail.cpp new file mode 100644 index 0000000000000..2f516f8fbc916 --- /dev/null +++ b/test/std/input.output/iostream.format/quoted.manip/quoted_char.fail.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// quoted + +#include <iomanip> +#include <sstream> +#include <string> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +void round_trip ( const char *p ) { + std::wstringstream ss; + ss << std::quoted(p); + std::string s; + ss >> std::quoted(s); + } + + + +int main() +{ + round_trip ( "Hi Mom" ); +} +#else +#error +#endif diff --git a/test/std/input.output/iostream.format/quoted.manip/quoted_traits.fail.cpp b/test/std/input.output/iostream.format/quoted.manip/quoted_traits.fail.cpp new file mode 100644 index 0000000000000..bdd362df19c99 --- /dev/null +++ b/test/std/input.output/iostream.format/quoted.manip/quoted_traits.fail.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// quoted + +#include <iomanip> +#include <sstream> +#include <string> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +template <class charT> +struct test_traits +{ + typedef charT char_type; +}; + +void round_trip ( const char *p ) { + std::stringstream ss; + ss << std::quoted(p); + std::basic_string<char, test_traits<char>> s; + ss >> std::quoted(s); + } + + + +int main() +{ + round_trip ( "Hi Mom" ); +} +#else +#error +#endif diff --git a/test/std/input.output/iostream.format/std.manip/resetiosflags.pass.cpp b/test/std/input.output/iostream.format/std.manip/resetiosflags.pass.cpp new file mode 100644 index 0000000000000..6c01fc057da43 --- /dev/null +++ b/test/std/input.output/iostream.format/std.manip/resetiosflags.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// T1 resetiosflags(ios_base::fmtflags mask); + +#include <iomanip> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +int main() +{ + { + testbuf<char> sb; + std::istream is(&sb); + assert(is.flags() & std::ios_base::skipws); + is >> std::resetiosflags(std::ios_base::skipws); + assert(!(is.flags() & std::ios_base::skipws)); + } + { + testbuf<char> sb; + std::ostream os(&sb); + assert(os.flags() & std::ios_base::skipws); + os << std::resetiosflags(std::ios_base::skipws); + assert(!(os.flags() & std::ios_base::skipws)); + } + { + testbuf<wchar_t> sb; + std::wistream is(&sb); + assert(is.flags() & std::ios_base::skipws); + is >> std::resetiosflags(std::ios_base::skipws); + assert(!(is.flags() & std::ios_base::skipws)); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + assert(os.flags() & std::ios_base::skipws); + os << std::resetiosflags(std::ios_base::skipws); + assert(!(os.flags() & std::ios_base::skipws)); + } +} diff --git a/test/std/input.output/iostream.format/std.manip/setbase.pass.cpp b/test/std/input.output/iostream.format/std.manip/setbase.pass.cpp new file mode 100644 index 0000000000000..e2776a5d1ab38 --- /dev/null +++ b/test/std/input.output/iostream.format/std.manip/setbase.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// T3 setbase(int base); + +#include <iomanip> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +int main() +{ + { + testbuf<char> sb; + std::istream is(&sb); + is >> std::setbase(8); + assert((is.flags() & std::ios_base::basefield) == std::ios_base::oct); + is >> std::setbase(10); + assert((is.flags() & std::ios_base::basefield) == std::ios_base::dec); + is >> std::setbase(16); + assert((is.flags() & std::ios_base::basefield) == std::ios_base::hex); + is >> std::setbase(15); + assert((is.flags() & std::ios_base::basefield) == 0); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os << std::setbase(8); + assert((os.flags() & std::ios_base::basefield) == std::ios_base::oct); + os << std::setbase(10); + assert((os.flags() & std::ios_base::basefield) == std::ios_base::dec); + os << std::setbase(16); + assert((os.flags() & std::ios_base::basefield) == std::ios_base::hex); + os << std::setbase(15); + assert((os.flags() & std::ios_base::basefield) == 0); + } + { + testbuf<wchar_t> sb; + std::wistream is(&sb); + is >> std::setbase(8); + assert((is.flags() & std::ios_base::basefield) == std::ios_base::oct); + is >> std::setbase(10); + assert((is.flags() & std::ios_base::basefield) == std::ios_base::dec); + is >> std::setbase(16); + assert((is.flags() & std::ios_base::basefield) == std::ios_base::hex); + is >> std::setbase(15); + assert((is.flags() & std::ios_base::basefield) == 0); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os << std::setbase(8); + assert((os.flags() & std::ios_base::basefield) == std::ios_base::oct); + os << std::setbase(10); + assert((os.flags() & std::ios_base::basefield) == std::ios_base::dec); + os << std::setbase(16); + assert((os.flags() & std::ios_base::basefield) == std::ios_base::hex); + os << std::setbase(15); + assert((os.flags() & std::ios_base::basefield) == 0); + } +} diff --git a/test/std/input.output/iostream.format/std.manip/setfill.pass.cpp b/test/std/input.output/iostream.format/std.manip/setfill.pass.cpp new file mode 100644 index 0000000000000..a4d923d70adee --- /dev/null +++ b/test/std/input.output/iostream.format/std.manip/setfill.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// template<charT> T4 setfill(charT c); + +#include <iomanip> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + os << std::setfill('*'); + assert(os.fill() == '*'); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os << std::setfill(L'*'); + assert(os.fill() == L'*'); + } +} diff --git a/test/std/input.output/iostream.format/std.manip/setiosflags.pass.cpp b/test/std/input.output/iostream.format/std.manip/setiosflags.pass.cpp new file mode 100644 index 0000000000000..5aaf38444ab14 --- /dev/null +++ b/test/std/input.output/iostream.format/std.manip/setiosflags.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// T2 setiosflags (ios_base::fmtflags mask); + +#include <iomanip> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +int main() +{ + { + testbuf<char> sb; + std::istream is(&sb); + assert(!(is.flags() & std::ios_base::oct)); + is >> std::setiosflags(std::ios_base::oct); + assert(is.flags() & std::ios_base::oct); + } + { + testbuf<char> sb; + std::ostream os(&sb); + assert(!(os.flags() & std::ios_base::oct)); + os << std::setiosflags(std::ios_base::oct); + assert(os.flags() & std::ios_base::oct); + } + { + testbuf<wchar_t> sb; + std::wistream is(&sb); + assert(!(is.flags() & std::ios_base::oct)); + is >> std::setiosflags(std::ios_base::oct); + assert(is.flags() & std::ios_base::oct); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + assert(!(os.flags() & std::ios_base::oct)); + os << std::setiosflags(std::ios_base::oct); + assert(os.flags() & std::ios_base::oct); + } +} diff --git a/test/std/input.output/iostream.format/std.manip/setprecision.pass.cpp b/test/std/input.output/iostream.format/std.manip/setprecision.pass.cpp new file mode 100644 index 0000000000000..0bea4b98623b9 --- /dev/null +++ b/test/std/input.output/iostream.format/std.manip/setprecision.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// T5 setprecision(int n); + +#include <iomanip> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +int main() +{ + { + testbuf<char> sb; + std::istream is(&sb); + is >> std::setprecision(10); + assert(is.precision() == 10); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os << std::setprecision(10); + assert(os.precision() == 10); + } + { + testbuf<wchar_t> sb; + std::wistream is(&sb); + is >> std::setprecision(10); + assert(is.precision() == 10); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os << std::setprecision(10); + assert(os.precision() == 10); + } +} diff --git a/test/std/input.output/iostream.format/std.manip/setw.pass.cpp b/test/std/input.output/iostream.format/std.manip/setw.pass.cpp new file mode 100644 index 0000000000000..9bd96984e5c98 --- /dev/null +++ b/test/std/input.output/iostream.format/std.manip/setw.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// T6 setw(int n); + +#include <iomanip> +#include <cassert> + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + testbuf() {} +}; + +int main() +{ + { + testbuf<char> sb; + std::istream is(&sb); + is >> std::setw(10); + assert(is.width() == 10); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os << std::setw(10); + assert(os.width() == 10); + } + { + testbuf<wchar_t> sb; + std::wistream is(&sb); + is >> std::setw(10); + assert(is.width() == 10); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os << std::setw(10); + assert(os.width() == 10); + } +} diff --git a/test/std/input.output/iostream.format/std.manip/version.pass.cpp b/test/std/input.output/iostream.format/std.manip/version.pass.cpp new file mode 100644 index 0000000000000..ca4fd3d463eeb --- /dev/null +++ b/test/std/input.output/iostream.format/std.manip/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +#include <iomanip> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} |