Move test into test/std subdirectory.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2014-12-20 01:40:03 +00:00
parent 669a8a5a19
commit a90c6dd460
4817 changed files with 13 additions and 0 deletions

View File

@@ -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");
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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");
}
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -0,0 +1,82 @@
//===----------------------------------------------------------------------===//
//
// 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> sb;
std::ostream os(&sb);
const void* n = 0;
os << n;
assert(os.good());
// %p is implementation defined.
// On some platforms (Windows), it's a hex number without
// any leading 0x like prefix.
// In that format, we assume a null pointer will yield 2 '0' hex digits
// for each 8 bits of address space.
assert(sb.str() == "0x0" || sb.str() == "(nil)" ||
sb.str() == std::string(sizeof(void*)*2,'0'));
}
{
testbuf<char> sb;
std::ostream os(&sb);
const void* n = &sb;
os << n;
assert(os.good());
}
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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));
}
}

View File

@@ -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));
}
}

View File

@@ -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...");
}
}

View File

@@ -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...");
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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
}

View File

@@ -0,0 +1,57 @@
//===----------------------------------------------------------------------===//
//
// 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()
{
{
std::ostream os((std::streambuf*)0);
assert(&os.seekp(5) == &os);
assert(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());
}
}

View File

@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// 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()
{
{
std::ostream os((std::streambuf*)0);
assert(&os.seekp(5, std::ios_base::beg) == &os);
assert(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());
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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), "");
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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()
{
}