41#define Bad std::ios_base::badbit
42#define Eof std::ios_base::eofbit
43#define Fail std::ios_base::failbit
44#define Good std::ios_base::goodbit
47template <
class charT,
class Traits>
53 std::basic_istream<charT, Traits>&
strm,
60 static const char*
const exnames[] = {
61 "none",
"std::ios_base::failure",
62 "streambuf_exception",
"unknown exception"
65 const char*
const caught_what = exnames [
caught];
69 "line %d: basic_istream<%s>::%s; "
70 "rdstate () == %{Is}, got %{Is}",
71 __LINE__, cname,
fun, rdstate,
strm.rdstate ());
74 if (
sb.throw_set_ &&
sb.ncalls (
sb.threw_) ==
sb.fail_when_) {
83 "line %d: basic_istream<%s>::%s failed "
84 "to propagate an exception thrown "
85 "by basic_filebuf; caught %s instead",
92 "line %d: basic_istream<%s>::%s propagated "
93 "an exception thrown by basic_filebuf when "
94 "ios_base::badbit is clear in exceptions",
95 __LINE__, cname,
fun);
101 const std::streamsize actual =
strm.gcount () - gcount;
104 "line %d: basic_istream<%s>::%s changed "
105 "gcount () from %d to %d after a failure; "
106 "either no change from 0 expected, or "
107 "an increase to %d from 0 expected",
108 __LINE__, cname,
fun,
109 gcount,
strm.gcount (),
sb.fail_when_ - 1);
117 "line %d: basic_istream<%s>::%s set %{Is} "
118 "but failed to throw ios_base::failure "
119 "when the same bit is set in exceptions",
120 __LINE__, cname,
fun, rdstate);
124 const std::streamsize actual =
strm.gcount () - gcount;
127 "line %d: basic_istream<%s>::%s changed "
128 "gcount () from %d to %d after a successful "
129 "extraction; a change from 0 to %d expected",
130 __LINE__, cname,
fun,
131 gcount,
strm.gcount (), nexpect);
137#define TRY_GET(expr) \
141 catch (const std::ios_base::failure&) { \
144 catch (Exception& e) { \
145 caught = ex_stream == e.id_ ? 2 : 3; \
169template <
class charT,
class Traits>
188 typedef std::basic_istream<charT, Traits> Istream;
189 typedef typename Istream::int_type int_type;
191 const int_type
val = int_type (
ival);
198 strm.exceptions (std::ios_base::iostate (exceptions));
200 const std::streamsize gcount =
strm.gcount ();
202 int_type got = Traits::eof ();
209 !rdstate, rdstate, exceptions,
caught);
215 const charT cval = Traits::to_char_type (
val);
216 const charT cgot = Traits::to_char_type (got);
219 "line %d: basic_istream<%s>::get () == %{#lc}, got %{#lc}",
220 __LINE__, cname, cval, cgot);
225 "line %d: basic_istream<%s>::get () changed "
226 "gcount () from %d to %d after a successful "
227 "extraction; 0 to 1 expected",
229 gcount,
strm.gcount ());
234template <
class charT>
237#define T charT (), cname, (UserTraits<charT>*)0, __LINE__
238#define TEST test_get_void
240 rw_info (0, 0, 0,
"27.6.1.3, p3 - std::basic_istream<%s>::get ()",
274template <
class charT,
class Traits>
297 typedef std::basic_istream<charT, Traits> Istream;
298 typedef typename Istream::int_type int_type;
305 strm.exceptions (std::ios_base::iostate (exceptions));
307 const std::streamsize gcount =
strm.gcount ();
309 typedef unsigned char UChar;
319 int (gcount), !rdstate, rdstate, exceptions,
caught);
324 "line %d: basic_istream<%s>::get (char_type& = %{#lc}),"
325 " expected %{#lc}", __LINE__, cname, got,
val);
328 "line %d: basic_istream<%s>::get (char_type&) "
329 "changed gcount () from %d to %d after a successful "
330 "extraction; 0 to 1 expected",
332 gcount,
strm.gcount ());
337template <
class charT>
343#define T charT (), cname, (UserTraits<charT>*)0, __LINE__
344#define TEST test_get_char
347 "27.6.1.3, p5 - std::basic_istream<%s>::get (char_type&)",
383#define MAXCHARS (4096U * 4U)
386template <
class charT,
class Traits>
427 typedef std::basic_istream<charT, Traits> Istream;
428 typedef typename Istream::int_type int_type;
430 const int_type delim = int_type (idelim);
437 strm.exceptions (std::ios_base::iostate (exceptions));
439 const std::streamsize gcount =
strm.gcount ();
441 typedef unsigned char UChar;
446 Traits::assign (got,
sizeof got /
sizeof *got,
charT (
'\xfe'));
450 if (delim != Traits::eof ()) {
451 fun =
"get(char_type*, streamsize, char_type)";
452 TRY_GET (
strm.get (got, std::streamsize (nread), delim));
455 fun =
"get(char_type*, streamsize)";
460 rdstate, exceptions,
caught);
466 "line %d: basic_istream<%s>::get (char_type*, "
467 "streamsize = %d).gcount () == %d, got %d",
468 __LINE__, cname, nread, nexpect,
strm.gcount ());
471 "line %d: basic_istream<%s>::get (char_type *s "
472 "= %{*Ac}, streamsize = %d); s[0] == '\\0', got %{#lc}",
473 __LINE__, cname,
int (
sizeof *got), got, nread, *got);
475 rw_assert (!Traits::compare (
sb.buf_, got, std::size_t (nexpect)),
477 "line %d: basic_istream<%s>::get (char_type* "
478 "= %{*Ac}, streamsize = %d) data mismatch",
479 __LINE__, cname, int (
sizeof *got), got, nread);
484template <
class charT>
490#define T charT (), cname, (UserTraits<charT>*)0, __LINE__
491#define TEST test_get_char_array
493 rw_info (0, 0, 0,
"27.6.1.3, p5 - std::basic_istream<%s>"
494 "::get (char_type*, streamsize)", cname);
543 char *
buf =
new char [
N];
545 for (
int i = 0;
i !=
N; ++
i) {
560 for (
int i = 0;
i <
N;
i += 256) {
563 buf [
'\n' +
i] =
'\0';
566 rw_info (0, 0, 0,
"27.6.1.3, p5 - std::basic_istream<%s>"
567 "::get (char_type*, streamsize, char_type)", cname);
579template <
class charT,
class Traits>
593 typedef std::basic_istream<charT, Traits> Istream;
594 typedef typename Istream::int_type int_type;
596 const int_type delim = int_type (idelim);
598 int in_failure, in_fail_when;
599 int out_failure, out_fail_when;
601 switch (failure & ~
Throw) {
603 in_failure = failure;
604 in_fail_when = fail_when;
612 out_failure = failure;
613 out_fail_when = fail_when;
617 in_failure = failure;
618 in_fail_when = fail_when;
619 out_failure = failure;
620 out_fail_when = fail_when;
624 Streambuf inbuf (
str, strsize, in_failure, in_fail_when);
626 Istream
strm (&inbuf);
628 strm.exceptions (std::ios_base::iostate (exceptions));
630 const std::streamsize gcount =
strm.gcount ();
632 typedef unsigned char UChar;
636 Streambuf outbuf (strsize, out_failure, out_fail_when);
640 if (delim != Traits::eof ()) {
641 fun =
"get(basic_streambuf<char_type, traits_type>&, char_type)";
645 fun =
"get(basic_streambuf<char_type, traits_type>&)";
650 nexpect, rdstate, exceptions,
caught);
656 "line %d: basic_istream<%s>::get (basic_streambuf"
657 "<char_type, traits_type>*).gcount () == %d, got %d",
658 __LINE__, cname, nexpect,
strm.gcount ());
660 rw_assert (!Traits::compare (inbuf.buf_, outbuf.buf_,
661 std::size_t (nexpect)), 0,
lineno,
662 "line %d: basic_istream<%s>::get (basic_streambuf"
663 "<char_type, traits_type>*) data mismatch",
669template <
class charT>
675#define T charT (), cname, (UserTraits<charT>*)0, __LINE__
676#define TEST test_get_streambuf
678 rw_info (0, 0, 0,
"27.6.1.3, p12 - std::basic_istream<%s>"
679 "::get (basic_streambuf<char_type, traits_type>*, char_type)",
739 rw_info (0, 0, 0,
"27.6.1.3, p15 - std::basic_istream<%s>"
740 "::get (basic_streambuf<char_type, traits_type>&)", cname);
750static int rw_opt_no_get_void;
751static int rw_opt_no_get_char;
752static int rw_opt_no_get_char_array;
753static int rw_opt_no_get_streambuf;
760#define TEST(T, arg) \
761 if (rw_opt_no_get_ ## arg) \
763 "basic_istream::get(%s) test disabled", #arg); \
765 test_get_ ## arg (T (), #T)
770 TEST (
char, char_array);
771 TEST (
char, streambuf);
773#ifndef _RWSTD_NO_WCHAR_T
775 TEST (
wchar_t,
void);
776 TEST (
wchar_t,
char);
777 TEST (
wchar_t, char_array);
778 TEST (
wchar_t, streambuf);
787int main (
int argc,
char *argv[])
789 return rw_test (argc, argv, __FILE__,
790 "lib.istream.unformatted",
791 "overloads of get() member function",
795 "|-no-get-char_array#"
796 "|-no-get-streambuf#",
799 &rw_opt_no_get_char_array,
800 &rw_opt_no_get_streambuf,
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
std::char_traits< S > Traits
_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_assert(int, const char *, int, const char *,...)