60 typedef std::basic_streambuf<char_type, traits_type>
Streambuf;
110 return traits_type::eof ();
115 return traits_type::eof ();
124 return traits_type::eof ();
127 virtual std::streamsize
131 return Streambuf::xsputn (
buf, bufsize);
139 pstrm_->setstate (std::ios_base::failbit);
152 std::basic_ios<char_type, traits_type> *
pstrm_;
158template <
class charT>
162template <
class charT>
168 if (ncalls_ [
which] == fail_when_ && throws_ ==
which)
171 return fails_ !=
which || ncalls_ [
which] != fail_when_;
175template <
class charT>
180 return traits_type::eof ();
182 if (traits_type::eq_int_type (
c, traits_type::eof ()))
183 return traits_type::not_eof (
c);
185 const std::ptrdiff_t pptr_off = this->pptr () - this->pbase ();
187 if ( this->pptr () == this->epptr ()
188 && this->epptr () < buf_ + bufsize_) {
189 this->setp (buf_, this->epptr () + 1);
190 this->pbump (pptr_off + 1);
191 *(this->pptr () - 1) = traits_type::to_char_type (
c);
195 return traits_type::eof ();
205#ifndef _RWSTD_NO_NATIVE_BOOL
221#ifdef _RWSTD_LONG_LONG
231#ifndef _RWSTD_NO_LONG_DOUBLE
240template <
class charT>
241struct test_num_put: std::num_put<charT, std::ostreambuf_iterator<charT> >
245 typedef std::num_put<charT, iter_type>
NumPut;
246 typedef std::ios_base
Ios;
257#define TEST(it, val) test (it, select_overload (val))
259#ifndef _RWSTD_NO_NATIVE_BOOL
293#ifdef _RWSTD_LONG_LONG
318template <
class charT>
324 if (throws_ ==
which)
327 if (fails_ ==
which) {
347template <
class charT>
350 typedef std::basic_ostream<charT, std::char_traits<charT> >
Ostream;
357#ifndef _RWSTD_UNCAUGHT_EXCEPTION
359 uncaught = std::uncaught_exception ();
368template <
class charT>
373 typedef std::basic_ostream<charT, std::char_traits<charT> > Ostream;
374 typedef typename Ostream::sentry Sentry;
376 const Sentry *pguard = 0;
380 "std::basic_ostream<%s>::sentry::sentry "
381 "(basic_ostream&)", cname);
384 static Ostream
strm (0);
386 strm.setf (std::ios_base::unitbuf);
389 pguard =
new Sentry (
strm);
408 Ostream tied (&tsb_tied);
409 Ostream
strm (&tsb_strm);
415 const Sentry guard (
strm);
418 "std::basic_ostream<%s>::sentry::sentry "
419 "(basic_ostream &s) called s.tie ()->flush() once; "
423 rw_info (0, 0, __LINE__,
"std::basic_ostream<%s>::sentry::operator "
424 "bool () const", cname);
427 "std::basic_ostream<%s>::sentry::operator bool() == true "
428 "after a successful construction", cname);
438 Ostream
strm (&tsb_strm);
445 Ostream tied (&tsb_tied);
452 const Sentry guard (
strm);
455 "std::basic_ostream<%s>::sentry::operator bool() == "
456 "false after a failed construction (stream.rdstate() "
457 "== %{Is})", cname,
strm.rdstate ());
466 Ostream
strm (&tsb_strm);
472 Ostream tied (&tsb_tied);
477 strm.setstate (std::ios_base::failbit);
481 const Sentry guard (
strm);
484 "std::basic_ostream<%s>::sentry::sentry(basic_ostream&) "
485 "unexpectedly called stream.tie()->flush() when "
486 "stream.good() == false", cname);
489 "std::basic_ostream<%s>::sentry::operator bool() == "
490 "false for a stream whose stream.rdstate() = %{Is}",
491 cname,
strm.rdstate ());
494#ifndef _RWSTD_NO_EXCEPTIONS
499 Ostream
strm (&tsb_strm);
502 Ostream tied (&tsb_tied);
521 const Sentry guard (
strm);
524 "std::basic_ostream<%s>::sentry::operator bool() == "
525 "true after it failed to flush a tied stream due to "
526 "an exception (stream.rdstate() == %{Is})",
527 cname,
strm.rdstate ());
531 "std::basic_ostream<%s>::sentry::sentry(basic_ostream&)"
532 " unexpectedly allowed an exception to propagate",
540 "std::basic_ostream<%s>::sentry::sentry(basic_ostream&) "
541 "unexpectedly affected the state of the stream as a result "
542 "pf an exception thrown during the flushing of a tied "
543 "stream; stream state = %{Is}", cname,
strm.rdstate ());
548 "std::basic_ostream<%s>::sentry::sentry(basic_ostream&) "
549 "failed to cause badbit to be set in stream's tied object "
550 "after an exception; tied stream's state = %{Is}",
551 cname, tied.rdstate ());
558 "std::basic_ostream<%s>::sentry::~sentry()", cname);
581 const Sentry guard (
strm);
587 "std::basic_ostream<%s>::sentry::~sentry() unexpectedly "
588 "called stream.flush () when ios::unitbuf is clear",
594 strm.setf (std::ios_base::unitbuf);
596 const Sentry guard (
strm);
602 "std::basic_ostream<%s>::sentry::~sentry() failed to call "
603 "stream.flush () when ios::unitbuf is set",
606#ifndef _RWSTD_NO_EXCEPTIONS
607# ifndef _RWSTD_NO_UNCAUGHT_EXCEPTION
617 strm.setf (std::ios_base::unitbuf);
629 "std::basic_ostream<%s>::sentry::~sentry() "
630 "unexpectedly called stream.flush() when "
631 "ios::unitbuf is set but uncaught_exception() "
632 "returns true", cname);
635 "std::uncaught_exception () == true when an exception "
636 "is pending (language runtime library error)");
650#define Boolalpha std::ios_base::boolalpha
651#define Dec std::ios_base::dec
652#define Fixed std::ios_base::fixed
653#define Hex std::ios_base::hex
654#define Internal std::ios_base::internal
655#define Left std::ios_base::left
656#define Oct std::ios_base::oct
657#define Right std::ios_base::right
658#define Scientific std::ios_base::scientific
659#define Showbase std::ios_base::showbase
660#define Showpoint std::ios_base::showpoint
661#define Showpos std::ios_base::showpos
662#define Skipws std::ios_base::skipws
663#define Unitbuf std::ios_base::unitbuf
664#define Uppercase std::ios_base::uppercase
665#define Bin std::ios_base::bin
666#define Adjustfield std::ios_base::adjustfield
667#define Basefield std::ios_base::basefield
668#define Floatfield std::ios_base::floatfield
669#define Nolock std::ios_base::nolock
670#define Nolockbuf std::ios_base::nolockbuf
672#define Bad std::ios_base::badbit
673#define Eof std::ios_base::eofbit
674#define Fail std::ios_base::failbit
675#define Good std::ios_base::goodbit
681template <
class charT,
class T>
696 typedef std::basic_ostream<charT, std::char_traits<charT> > Ostream;
698 charT charbuf [256] = { 0 };
706 if (failure &
Throw) {
728 os.imbue (std::locale (std::locale::classic (), &tnp));
731 os.flags (std::ios_base::fmtflags (fmtflags));
732 os.width (std::streamsize (width));
733 os.exceptions (std::ios_base::iostate (exceptions));
738 enum { E_unknown = 1, E_failure };
741 const char *caught_what =
"none (none thrown)";
748 caught_what =
"streambuf_failure";
752 caught_what =
"num_put_overload";
754 catch (
const std::ios_base::failure&) {
756 caught_what =
"std::ios_base::failure";
760 caught_what =
"unknown exception";
764 char cbuf [256] =
"";
765 for (std::size_t
i = 0;
i !=
sizeof cbuf &&
str [
i]; ++
i)
766 cbuf [
i] =
char (charbuf [
i]);
768 rw_assert (0 == std::strcmp (cbuf,
str), __FILE__, line1,
769 "%d. std::basic_ostream<%s>::operator<<(%s = %{#lc}) "
770 "inserted \"%s\", expected \"%s\"",
771 line2, cname, tname, cbuf,
str);
775 rw_assert (rdstate ==
os.rdstate (), __FILE__, line1,
776 "%d. std::basic_ostream<%s>::operator<<(%s = %{#lc})"
777 ".rdstate() == %{Is}, got %{Is}",
778 line2, cname, tname,
val, rdstate,
os.rdstate ());
784#ifdef _RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE
791 "%d. std::basic_ostream<%s>::operator<<(%s = %{#lc})"
792 ".width () == 0, got %d",
793 line2, cname, tname,
val,
os.width ());
798 pass = !(exceptions &
os.rdstate () &&
caught != E_failure);
801 "%d. std::basic_ostream<%s>::operator<<(%s = %{#lc}) "
802 "set %{Is} but failed to throw ios_base::failure "
803 "when the same bit is set in exceptions",
804 line2, cname, tname,
val, rdstate);
816 "%d. std::basic_ostream<%s>::operator<<(%s = %{#lc}) "
817 "failed to propagate an exception thrown by "
818 "basic_filebuf; caught %s instead",
819 line2, cname, tname,
val, caught_what);
823 "%d. std::basic_ostream<%s>::operator<<(%s = %{#lc}) "
824 "propagated an exception thrown by basic_filebuf "
825 "when ios_base::badbit is clear in exceptions",
826 line2, cname, tname,
val);
836 if (exceptions &
Bad)
838 "%d. std::basic_ostream<%s>::operator<<(%s = %{#lc}) "
839 "failed to propagate exception thrown by "
840 "basic_filebuf; caught %s instead",
841 line2, cname, tname,
val, caught_what);
844 "%d. std::basic_ostream<%s>::operator<<(%s = %{#lc}) "
845 "propagated an exception thrown by basic_filebuf"
846 "when ios_base::badbit is clear in exceptions",
847 line2, cname, tname,
val);
853template <
class charT>
861bool is_char (
const signed char*) {
return true; }
862bool is_char (
const unsigned char*) {
return true; }
864template <
class charT>
867#ifndef _RWSTD_NO_WCHAR_T
875template <
class charT,
class T>
889 "std::operator<<(basic_ostream<%s>&, %s)", cname, tname);
892 "std::basic_ostream<%s>::operator<<(%s)", cname, tname);
899 typedef std::basic_ostream<charT, std::char_traits<charT> > Ostream;
901#define T charT (), line, __LINE__
902#define TEST test_formatted
956template <
class charT>
960#define T(val) charT (), __LINE__, val
963#define TEST test_formatted
974 TEST (
T (
'a'), 0, 0,
"a");
975 TEST (
T (
'A'), 0, 0,
"A");
976 TEST (
T (
'@'), 0, 1,
"@");
977 TEST (
T (
'#'), 0, 2,
" #");
981#ifndef _RWSTD_NO_NATIVE_WCHAR_T
985 TEST (
T (
L'b'), 0, 0,
"b");
986 TEST (
T (
L'B'), 0, 0,
"B");
997 typedef signed char SChar;
999 TEST (
T (SChar (
'b')), 0, 0,
"b");
1000 TEST (
T (SChar (
'B')), 0, 0,
"B");
1004 typedef unsigned char UChar;
1011#ifndef _RWSTD_NO_NATIVE_BOOL
1015 TEST (
T (
false), 0, 0,
"0");
1016 TEST (
T (
true), 0, 0,
"1");
1029 TEST (
T (
short ( 0)), 0, 0,
"0");
1030 TEST (
T (
short ( 1)), 0, 0,
"1");
1031 TEST (
T (
short (-1)), 0, 0,
"-1");
1033#if SHRT_MAX == 32767
1041#elif SHRT_MAX == 2147483647
1053 typedef unsigned short UShort;
1055 TEST (
T (UShort ( 0)), 0, 0,
"0");
1056 TEST (
T (UShort ( 1)), 0, 0,
"1");
1057 TEST (
T (UShort (255)), 0, 0,
"255");
1059#if USHRT_MAX == 0xffffU
1064#elif USHRT_MAX == 0xffffffffU
1073 TEST (
T ( 0), 0, 0,
"0");
1074 TEST (
T ( 1), 0, 0,
"1");
1075 TEST (
T (-1), 0, 0,
"-1");
1085#elif INT_MAX == 2147483647
1093#elif INT_MAX == 9223372036854775807
1105 TEST (
T ( 0), 0, 0,
"0");
1106 TEST (
T ( 1), 0, 0,
"1");
1107 TEST (
T (255), 0, 0,
"255");
1109#if UINT_MAX == 0xffffU
1114#elif UINT_MAX == 0xffffffffU
1119#elif UINT_MAX == 0xffffffffffffffffU
1128 TEST (
T ( 0
L), 0, 0,
"0");
1129 TEST (
T ( 1L), 0, 0,
"1");
1130 TEST (
T (-1L), 0, 0,
"-1");
1132#if LONG_MAX == 32767L
1140#elif LONG_MAX == 2147483647L
1148#elif LONG_MAX == 9223372036854775807L
1161 TEST (
T ( 0UL), 0, 0,
"0");
1162 TEST (
T ( 1UL), 0, 0,
"1");
1163 TEST (
T (257UL), 0, 0,
"257");
1165#if ULONG_MAX == 0xffffUL
1170#elif ULONG_MAX == 0xffffffffUL
1175#elif ULONG_MAX == 0xffffffffffffffffUL
1182#ifdef _RWSTD_LONG_LONG
1188 TEST (
T (LongLong ( 0)), 0, 0,
"0");
1189 TEST (
T (LongLong ( 1)), 0, 0,
"1");
1190 TEST (
T (LongLong (-1)), 0, 0,
"-1");
1195 if (_RWSTD_LLONG_MAX == 32767L) {
1197 TEST (
T (_RWSTD_LLONG_MAX), 0, 0,
"32767");
1198 TEST (
T (_RWSTD_LLONG_MIN), 0, 0,
"-32768");
1200 TEST (
T (_RWSTD_LLONG_MAX),
Hex, 0,
"7fff");
1201 TEST (
T (_RWSTD_LLONG_MIN),
Hex, 0,
"8000");
1203 else if (_RWSTD_LLONG_MAX == 2147483647L) {
1205 TEST (
T (_RWSTD_LLONG_MAX), 0, 0,
"2147483647");
1206 TEST (
T (_RWSTD_LLONG_MIN), 0, 0,
"-2147483648");
1208 TEST (
T (_RWSTD_LLONG_MAX),
Hex, 0,
"7fffffff");
1209 TEST (
T (_RWSTD_LLONG_MIN),
Hex, 0,
"80000000");
1212 else if (_RWSTD_LLONG_MAX > 2147483647L) {
1214 TEST (
T (_RWSTD_LLONG_MAX), 0, 0,
"9223372036854775807");
1215 TEST (
T (_RWSTD_LLONG_MIN), 0, 0,
"-9223372036854775808");
1217 TEST (
T (_RWSTD_LLONG_MAX),
Hex, 0,
"7fffffffffff");
1218 TEST (
T (_RWSTD_LLONG_MIN),
Hex, 0,
"800000000000");
1227 TEST (
T (ULongLong ( 0)), 0, 0,
"0");
1228 TEST (
T (ULongLong ( 1)), 0, 0,
"1");
1229 TEST (
T (ULongLong (257)), 0, 0,
"257");
1231 if (_RWSTD_ULLONG_MAX == 0xffffUL) {
1232 TEST (
T (_RWSTD_ULLONG_MAX), 0, 0,
"65535");
1233 TEST (
T (_RWSTD_ULLONG_MAX),
Hex, 0,
"ffff");
1235 else if (_RWSTD_ULLONG_MAX == 0xffffffffUL) {
1236 TEST (
T (_RWSTD_ULLONG_MAX), 0, 0,
"4294967295");
1237 TEST (
T (_RWSTD_ULLONG_MAX),
Hex, 0,
"ffffffff");
1239 else if (_RWSTD_ULLONG_MAX > 0xffffffffUL) {
1240 TEST (
T (_RWSTD_ULLONG_MAX), 0, 0,
"18446744073709551615");
1241 TEST (
T (_RWSTD_ULLONG_MAX),
Hex, 0,
"ffffffffffffffff");
1248 TEST (
T ( 0.0f), 0, 0,
"0");
1249 TEST (
T ( 1.0f), 0, 0,
"1");
1250 TEST (
T (-2.1f), 0, 0,
"-2.1");
1255 TEST (
T (3.1415926f), 0, 0,
"3.14159");
1261 TEST (
T (12.3456789f),
Fixed, 0,
"12.345679");
1265 TEST (
T ( 0.0), 0, 0,
"0");
1266 TEST (
T ( 2.0), 0, 0,
"2");
1267 TEST (
T (-4.2), 0, 0,
"-4.2");
1272 TEST (
T (1.23456789), 0, 0,
"1.23457");
1278 TEST (
T (12.3456789),
Fixed, 0,
"12.345679");
1280#ifndef _RWSTD_NO_LONG_DOUBLE
1284 TEST (
T ( 0.0L), 0, 0,
"0");
1285 TEST (
T ( 3.0L), 0, 0,
"3");
1286 TEST (
T (-5.3L), 0, 0,
"-5.3");
1291 TEST (
T (1.23456789L), 0, 0,
"1.23457");
1297 TEST (
T (12.3456789L),
Fixed, 0,
"12.345679");
1303 TEST (
T ((
void*)0), 0, 0, 0 );
1304 TEST (
T ((
void*)1), 0, 0, 0);
1305 TEST (
T ((
void*)0x2345), 0, 0, 0);
1309 TEST (
T (
"a"), 0, 0,
"a");
1310 TEST (
T (
"b"), 0, -1,
"b");
1311 TEST (
T (
"ab"), 0, 0,
"ab");
1312 TEST (
T (
"abc"), 0, 4,
" abc");
1313 TEST (
T (
"def"),
Left, 5,
"def<<",
'<');
1330#define SCH(val) charT (), __LINE__, (const signed char*)val
1334 TEST (
SCH (
"AB"), 0, 0,
"AB");
1335 TEST (
SCH (
"ABC"), 0, 4,
" ABC");
1348#define UCH(val) charT (), __LINE__, (const unsigned char*)val
1352 TEST (
UCH (
"YZ"), 0, 0,
"YZ");
1353 TEST (
UCH (
"XYZ"), 0, 4,
" XYZ");
1367template <
class charT>
1373 "std::basic_ostream<%s>::flush() ", cname);
1375 typedef std::basic_ostream<charT, std::char_traits<charT> > Ostream;
1376 typedef std::basic_streambuf<charT, std::char_traits<charT> >
Streambuf;
1380 Ostream
strm (&tsb);
1387 "std::basic_ostream<%s>::flush() called rdbuf()->sync() "
1388 "once; got %d times",
1394 Ostream
strm (&tsb);
1404 "std::basic_ostream<%s>::flush() called rdbuf()->sync() "
1405 "once; got %zu times",
1408 rw_assert (std::ios_base::badbit ==
strm.rdstate (), 0, __LINE__,
1409 "std::basic_ostream<%s>::flush() failed to set badbit "
1410 "after rdbuf()->pubsync() failed; state = %{Is}",
1411 cname,
strm.rdstate ());
1418 Ostream
strm (&tsb);
1420 strm.setstate (std::ios_base::failbit);
1427 "std::basic_ostream<%s>::flush() unexpectedly made "
1428 "%zu calls to rdbuf()->sync() when rdstate () == "
1432 rw_assert (std::ios_base::failbit ==
strm.rdstate (), 0, __LINE__,
1433 "std::basic_ostream<%s>::flush() unexpectedly changed "
1434 "state from std::ios_base::failbit to %{Is}",
1435 cname,
strm.rdstate ());
1441template <
class charT>
1446 rw_note (0, 0, __LINE__,
"sentry tests disabled");
1452 rw_note (0, 0, __LINE__,
"tests of formatted functions disabled");
1458 rw_note (0, 0, __LINE__,
"tests of unformatted functions disabled");
1466 rw_note (0, 0, __LINE__,
"flush tests disabled");
1478#ifndef _RWSTD_NO_WCHAR_T
1491 return rw_test (argc, argv, __FILE__,
1499 "|-no-exceptions~ ",
void test_formatted(charT, int line1, int line2, T val, const char *str, int fmtflags, int width, int fill, int rdstate, int exceptions, int failure=0, int fail_when=1)
num_put_overload select_overload(bool)
#define _RWSTD_ASSERT(ignore)
#define _RWSTD_CONST_CAST(T, x)
const char * type_name() const
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
std::basic_ostream< charT, std::char_traits< charT > > Ostream
virtual iter_type do_put(iter_type it, std::ios_base &f, char_type fill, bool v) const
test_num_put(std::size_t refs=0)
std::num_put< charT, iter_type > NumPut
std::ostreambuf_iterator< charT > iter_type
virtual iter_type do_put(iter_type it, Ios &fl, char_type fill, long double val) const
virtual iter_type do_put(iter_type it, Ios &fl, char_type fill, unsigned long val) const
virtual iter_type do_put(iter_type it, Ios &fl, char_type fill, const void *val) const
virtual iter_type do_put(iter_type it, Ios &fl, char_type fill, long val) const
virtual iter_type do_put(iter_type it, Ios &fl, char_type fill, double val) const
virtual iter_type do_put(iter_type it, Ios &fl, char_type fill, bool val) const
iter_type test(iter_type, num_put_overload) const
virtual std::streamsize xsputn(const char_type *buf, std::streamsize bufsize)
virtual std::streamsize showmanyc()
bool test(streambuf_failure) const
test_streambuf(charT *buf, std::streamsize bufsize)
virtual pos_type seekoff(off_type, std::ios_base::seekdir, std::ios_base::openmode)
Streambuf::int_type int_type
virtual int_type pbackfail(int_type=traits_type::eof())
std::char_traits< charT > traits_type
Streambuf::pos_type pos_type
virtual int_type underflow()
streambuf_failure throws_
std::basic_streambuf< char_type, traits_type > Streambuf
virtual pos_type seekpos(pos_type, std::ios_base::openmode)
std::basic_ios< char_type, traits_type > * pstrm_
test_streambuf(std::basic_ios< char_type, traits_type > *pstrm)
virtual std::streamsize xsgetn(char_type *, std::streamsize)
Streambuf::off_type off_type
virtual int_type overflow(int_type=traits_type::eof())
virtual Streambuf * setbuf(char_type *, std::streamsize)