38template <
class charT,
class Traits>
39struct Streambuf: std::basic_streambuf<charT, Traits>
41 typedef std::basic_streambuf<charT, Traits>
Base;
68 return this->eback ();
76 return this->egptr ();
80#ifndef _RWSTD_NO_EXCEPTIONS
83 throw (
const char*)
"showmanyc";
91 if (this->gptr () ==
end_)
92 return traits_type::eof ();
96#ifndef _RWSTD_NO_EXCEPTIONS
98 throw (
const char*)
"underflow";
102 return traits_type::eof ();
109 return traits_type::eof ();
111 this->setg (this->eback (), this->gptr (), this->gptr () + 1);
112 return traits_type::to_int_type (*this->gptr ());
143 "%{?}istream%{:}%{?}wistream"
144 "%{:}basic_istream<%s, %s>%{;}%{;}",
145 'c' == *cname &&
'c' == *tname,
146 'w' == *cname &&
'c' == *tname,
150 "std::%{$ISTREAM}::readsome (char_type*, streamsize)");
155extern const std::ios_base::iostate
157 std::ios_base::badbit,
158 std::ios_base::eofbit,
159 std::ios_base::failbit,
160 std::ios_base::goodbit,
161 std::ios_base::badbit | std::ios_base::eofbit,
162 std::ios_base::badbit | std::ios_base::failbit,
163 std::ios_base::eofbit | std::ios_base::failbit,
164 std::ios_base::badbit | std::ios_base::eofbit | std::ios_base::failbit
170template <
class charT,
class Traits>
179 typedef std::basic_istream<charT, Traits> Istream;
181 static unsigned iter = 0;
189 const char* err_type = 0;
204 err_type =
"returned EOF";
219 is.good () ?
j <
k ? int (
j) < l ?
j
227 std::streamsize nread = -1;
233 "%{$ISTREAM}(%{*Ac}).readsome(%p, %d)",
234 int (
sizeof *cbuf), cbuf,
buf,
j);
236#ifndef _RWSTD_NO_EXCEPTIONS
242 if (
k % 2 && !is.bad ())
243 is.exceptions (std::ios_base::badbit);
246 nread = is.readsome (
buf,
j);
248 catch (
const char *
s) {
256 "%{$FCALL} threw an exception of unexpected type");
265 "%{$FCALL} unexpectedly propagated an exception");
269 nread = is.readsome (
buf,
j);
277 const std::streamsize extracted =
sb.pubgptr () -
sb.pubeback ();
279 rw_assert (extract == extracted, 0, __LINE__,
280 "%{$FCALL} expected to extract %d chars, got %u; "
281 "initial state = %{Is}, underflow %s at extraction %u",
282 extract, extracted,
states [
i],
289 rw_assert (cbuf + extract ==
sb.pubgptr (), 0, __LINE__,
290 "%{$FCALL} expected to extract %d chars, got %u; "
291 "initial state = %{Is}, underflow %s at extraction %u",
292 extract, extracted,
states [
i],
298 rw_assert (0 == std::char_traits<charT>::compare (
buf, cbuf, extract),
300 "%{$FCALL} expected to extract the first %d chars, got %{*Ac}",
301 extract,
int (
sizeof *
buf),
buf);
307 rw_assert (extract == is.gcount (), 0, __LINE__,
308 "%{$FCALL}: gcount() == %d, got %d; initial state = %{Is}, "
309 "underflow %s at extraction %u",
310 extract, is.gcount (),
states [
i],
318 std::ios_base::iostate expect_state =
states [
i];
322#ifndef _RWSTD_NO_EXCEPTIONS
330 expect_state = std::ios_base::badbit;
332 expect_state = std::ios_base::eofbit;
334 expect_state = std::ios_base::goodbit;
339 expect_state = std::ios_base::eofbit;
341 expect_state = std::ios_base::goodbit;
350 expect_state =
states [
i] | std::ios_base::failbit;
353 rw_assert (is.rdstate () == expect_state, 0, __LINE__,
354 "%{$FCALL}: rdstate() == %{Is}, got %{Is}; "
355 "extracted %u characters; "
356 "initial state = %{Is}, underflow %s at extraction %u",
357 expect_state, is.rdstate (), extracted,
366template <
class charT,
class Traits>
368 const char *cname,
const char *tname)
375 const charT cbuf[] = {
' ',
'a',
' ',
'b',
'c',
'\0' };
376 const unsigned cbuf_size =
sizeof cbuf /
sizeof *cbuf;
384 for (
unsigned j = 0;
j != cbuf_size - 1; ++
j) {
387 for (
unsigned k = 0;
k !=
j + 1; ++
k) {
390 for (
int l = -4; l != int (
k); ++l) {
395 for (
unsigned m = 0;
m != 2; ++
m, ++iter) {
402 if (1U ==
m &&
int (
k) < l)
406 cbuf_size,
i,
j,
k, l,
m);
418static int opt_char_traits;
419static int opt_user_traits;
429#define TEST(CharT, Traits) \
430 test_readsome ((CharT*)0, (Traits*)0, #CharT, #Traits)
432 if (
rw_note (0 <= opt_char && 0 <= opt_char_traits, 0, __LINE__,
433 "basic_istream<char, char_traits<char>>::readsome() "
435 TEST (
char, char_traits<char>);
437 if (
rw_note (0 <= opt_char && 0 <= opt_user_traits, 0, __LINE__,
438 "basic_istream<char, UserTraits<char>>::readsome() "
442#ifndef _RWSTD_NO_WCHAR_T
444 if (
rw_note (0 <= opt_wchar && 0 <= opt_char_traits, 0, __LINE__,
445 "basic_istream<wchar_t, char_traits<wchar_t>>::readsome() "
447 TEST (
wchar_t, char_traits<wchar_t>);
449 if (
rw_note (0 <= opt_wchar && 0 <= opt_user_traits, 0, __LINE__,
450 "basic_istream<wchar_t, UserTraits<wchar_t>>::readsome() "
461int main (
int argc,
char *argv[])
463 return rw_test (argc, argv, __FILE__,
464 "istream.unformatted",
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
std::char_traits< S > Traits
void test_readsome(const charT *cbuf, const Traits *, unsigned cbuf_size, unsigned i, unsigned j, unsigned k, int l, unsigned m)
const std::ios_base::iostate states[]
void memfun_info(int line, const char *cname, const char *tname)
#define TEST(CharT, Traits)
#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 *,...)
const charT * pubeback() const
std::basic_streambuf< charT, Traits > Base
const charT * pubgptr() const
std::streamsize showmanyc()
Streambuf(const charT *gbeg, const charT *gend)
Base::traits_type traits_type
const charT * pubegptr() const