126 "%{?}istream%{:}%{?}wistream"
127 "%{:}basic_istream<%s, %s>%{;}%{;}",
128 'c' == *cname &&
'c' == *tname,
129 'w' == *cname &&
'c' == *tname,
134 "%{$ISTREAM}::sentry");
138 rw_info (0, 0,
line,
"std::%{$SENTRY}::%{@}", fname);
143template <
class charT>
144struct Ctype: std::ctype<charT>
146 typedef std::ctype<charT>
Base;
150 std::ctype_base::mask
table_ [256];
160 if (
m & std::ctype_base::space)
162 return Base::is (
m,
c);
167 std::ctype_base::mask *
m)
const {
168 return Base::is (from, to,
m);
174 for (; from != to && !
do_is (
m, *from); ++from);
181 for (; from != to &&
do_is (
m, *from); ++from);
193 table_ [
i] = std::ctype_base::mask ();
195 typedef unsigned char UChar;
201template <
class charT,
class Traits>
202struct Streambuf: std::basic_streambuf<charT, Traits>
204 typedef std::basic_streambuf<charT, Traits>
Base;
216 return this->eback ();
220 return this->gptr ();
224 return this->egptr ();
229 return Base::sync ();
234template <
class charT,
class Traits>
236 const char *cname,
const char *tname)
238 typedef std::basic_istream<charT, Traits> Istream;
239 typedef typename Istream::sentry Sentry;
241 memfun_info (__LINE__, cname, tname,
"sentry (%{$ISTREAM}&, bool)");
243 const charT cbuf[] = {
'a',
'b',
'c',
'd',
'e',
' ',
'f',
'\0' };
245 const std::ios_base::iostate
states[] = {
246 std::ios_base::badbit,
247 std::ios_base::eofbit,
248 std::ios_base::failbit,
249 std::ios_base::goodbit,
250 std::ios_base::badbit | std::ios_base::eofbit,
251 std::ios_base::badbit | std::ios_base::failbit,
252 std::ios_base::eofbit | std::ios_base::failbit,
253 std::ios_base::badbit | std::ios_base::eofbit | std::ios_base::failbit
265 for (
unsigned j = 0;
j != 2; ++
j ) {
267 sb (cbuf, cbuf +
sizeof cbuf /
sizeof *cbuf);
273 const bool flush_called = is.good () && 0 != is.tie ();
275 const Sentry guard (is, 0 !=
j);
279 rw_assert (flush_called ==
sb.nsyncs_, 0, __LINE__,
280 "%u. basic_istream<%s, %s>::sentry::sentry"
281 "(basic_istream &is, bool noskipws = %d); "
282 "expected to call is.flush () %d times, got %d"
283 "initial is.state () = %{Is}, is.flags() & "
285 iter, cname, tname, 0 !=
j, flush_called,
sb.nsyncs_,
286 states [
i], is.flags () & std::ios_base::skipws);
302 for (
unsigned j = 0;
j != 2; ++
j ) {
303 for (
unsigned k = 0;
k != 2; ++
k ) {
309 sb (cbuf, cbuf +
sizeof cbuf /
sizeof *cbuf);
316 is.setf (std::ios_base::skipws);
318 is.unsetf (std::ios_base::skipws);
320 const std::locale
loc =
321 is.imbue (std::locale (is.getloc (), &ctp));
334 && is.flags () & std::ios_base::skipws
337 const Sentry guard (is, 0 !=
j);
341 rw_assert (cbuf + extract ==
sb.pubgptr (), 0, __LINE__,
342 "%u. %{$SENTRY}::sentry"
343 "(%{$ISTREAM} &is, bool noskipws "
344 "= %b); expected to extract %d "
345 "whitespace chars ('%c') from %{*Ac}, "
346 "extracted %u; initial is.state () = "
347 "%{Is}, is.flags() & ios::skipws = %d",
348 iter,
j, extract + 0, char (wc),
349 int (
sizeof (*cbuf)), cbuf,
350 sb.pubgptr () -
sb.pubeback (),
354 rw_assert (0 == is.gcount (), 0, __LINE__,
355 "%u. %{$SENTRY}::sentry"
356 "(%{$ISTREAM} &is = %{*Ac}, bool noskipws "
357 "= %b); changed is.gcount() from 0 to %i",
358 iter, int (
sizeof (*cbuf)), cbuf,
j,
370template <
class charT,
class Traits>
372 const char *cname,
const char *tname)
374 typedef std::basic_istream<charT, Traits> Istream;
375 typedef typename Istream::sentry Sentry;
377 memfun_info (__LINE__, cname, tname,
"operator bool () const");
379 const charT cbuf[] = {
'a',
'b',
'c',
'd',
'e',
' ',
'f',
'\0' };
381 const std::ios_base::iostate
states[] = {
382 std::ios_base::badbit,
383 std::ios_base::eofbit,
384 std::ios_base::failbit,
385 std::ios_base::goodbit,
386 std::ios_base::badbit | std::ios_base::eofbit,
387 std::ios_base::badbit | std::ios_base::failbit,
388 std::ios_base::eofbit | std::ios_base::failbit,
389 std::ios_base::badbit | std::ios_base::eofbit | std::ios_base::failbit
406 for (
unsigned j = 0;
j != 2; ++
j ) {
407 for (
unsigned k = 0;
k != 2; ++
k ) {
413 sb (cbuf, cbuf +
sizeof cbuf /
sizeof *cbuf);
420 is.setf (std::ios_base::skipws);
422 is.unsetf (std::ios_base::skipws);
424 const std::locale
loc =
425 is.imbue (std::locale (is.getloc (), &ctp));
433 const Sentry guard (is, 0 !=
j);
438 const bool success = !is.good () == !guard;
442 "(%{$ISTREAM} &is, bool noskipws "
443 "= %d).operator bool() == %d; initial "
444 "is.state() = %{Is}, is.flags() & "
460static int opt_char_traits;
461static int opt_user_traits;
467#define TEST(what, charT, Traits) \
468 test_ ## what ((charT*)0, (Traits*)0, #charT, #Traits)
472 if (
rw_note (0 <= opt_char && 0 <= opt_char_traits, 0, __LINE__,
473 "istream::sentry tests disabled")) {
474 TEST (ctor,
char, char_traits<char>);
475 TEST (ok,
char, char_traits<char>);
478 if (
rw_note (0 <= opt_char && 0 <= opt_user_traits, 0, __LINE__,
479 "basic_istream<char, UserTraits<char>::sentry "
485#ifndef _RWSTD_NO_WCHAR_T
487 if (
rw_note (0 <= opt_wchar && 0 <= opt_char_traits, 0, __LINE__,
488 "wistream::sentry tests disabled")) {
489 TEST (ctor,
wchar_t, char_traits<wchar_t>);
490 TEST (ok,
wchar_t, char_traits<wchar_t>);
493 if (
rw_note (0 <= opt_wchar && 0 <= opt_user_traits, 0, __LINE__,
494 "basic_istream<wchar_t, UserTraits<wchar_t>::sentry "
508int main (
int argc,
char *argv[])
510 return rw_test (argc, argv, __FILE__,
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
std::char_traits< S > Traits
const std::ios_base::iostate states[]
void test_ctor(const charT *, const Traits *, const char *cname, const char *tname)
void test_ok(const charT *, const Traits *, const char *cname, const char *tname)
void memfun_info(int line, const char *cname, const char *tname, const char *fname)
#define TEST(what, charT, Traits)
#define _RWSTD_SPECIALIZED_CLASS
#define _RWSTD_UNUSED(arg)
#define _RWSTD_CONST_CAST(T, x)
_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 *,...)
_TEST_EXPORT int rw_fprintf(rw_file *, const char *,...)
std::ctype_base::mask table_[256]
const charT * do_scan_is(std::ctype_base::mask m, const charT *from, const charT *to) const
const charT * do_is(const charT *from, const charT *to, std::ctype_base::mask *m) const
bool do_is(std::ctype_base::mask m, charT c) const
const charT * do_scan_not(std::ctype_base::mask m, const charT *from, const charT *to) const
Ctype(unsigned ref, charT white)
const charT * pubeback() const
std::basic_streambuf< charT, Traits > Base
const charT * pubgptr() const
Streambuf(const charT *gbeg, const charT *gend)
const charT * pubegptr() const