37#define EOF (_RWSTD_INT_MIN + 2)
40#define NOT_EOF (_RWSTD_INT_MIN + 1)
43#define IGN _RWSTD_INT_MIN
53template <
class charT,
class Traits>
54struct PubBuf: std::basic_stringbuf<charT, Traits>
56 typedef std::basic_stringbuf<charT>
Base;
81 return this->seekoff (
off,
way);
85 std::ios_base::openmode
which) {
90 return this->seekpos (
pos);
108template <
class charT>
111 typedef std::char_traits<charT>
Base;
133 Traits tid,
const char *tname)
150static int stringbuf_capacity;
151static char long_string [4096];
155template <
class charT,
class Traits>
171 typedef std::basic_stringbuf<charT, Traits, Allocator> Stringbuf;
173 typedef typename Stringbuf::int_type int_type;
174 typedef typename Stringbuf::off_type off_type;
175 typedef typename Stringbuf::pos_type pos_type;
178 rw_note (0, 0, 0,
"test on line %d disabled",
line);
183 arg0 = Traits::eof ();
185 if (
EOF == ret_expect)
186 ret_expect = Traits::eof ();
189 static charT wstr [4096];
190 static charT warg [4096];
192 std::size_t wstr_len =
sizeof wstr /
sizeof *wstr;
193 std::size_t warg_len =
sizeof warg /
sizeof *warg;
198 const std::ios_base::openmode openmode = std::ios_base::openmode (
mode);
203 Stringbuf sb_m (openmode);
204 Stringbuf sb_s (wstr);
205 Stringbuf sb_s_m (wstr, openmode);
208 (
str ? -1 <
mode ? &sb_s_m : &sb_s : -1 <
mode ? &sb_m : &sb_0);
210 if (stringbuf_capacity < 0)
214 if (gbump &&
IGN != gbump) {
223 const int_type arg_int = int_type (arg0);
224 const off_type arg_off = off_type (arg0);
225 const pos_type arg_pos = arg_off;
227 const std::ios_base::seekdir arg_way = std::ios_base::seekdir (arg1);
228 const std::ios_base::openmode arg_which = std::ios_base::openmode (arg2);
233 switch (pfid->
vfun_) {
238 if (std::strchr (pfid->
strarg_,
'@'))
239 arg0 = int (warg_len);
241 RW_ASSERT (std::size_t (arg0) <
sizeof wstr /
sizeof *wstr);
242 ret = int (pbuf->sputn (warg, std::streamsize (arg0)));
246 ret = int (pbuf->sputn (pbuf->
Pbase (), std::streamsize (arg0)));
267 ret =
IGN == arg2 ? pbuf->
Seekoff (arg_off, arg_way)
268 : pbuf->
Seekoff (arg_off, arg_way, arg_which);
273 : pbuf->
Seekpos (arg_pos, arg_which);
279 const int pback_pos = int (pbuf->
Gptr () - pbuf->
Eback ());
283 const int read_pos = int (pbuf->
Egptr () - pbuf->
Gptr ());
287 const int write_pos = int (pbuf->
Epptr () - pbuf->
Pptr ());
296 "%{?}basic_%{:}%{?}w%{;}%{;}stringbuf%{?}<%s%{?}, %s%{;}>%{;}" \
297 "(%{?}%{*Ac}%{?}, %{Io}%{;}%{:}%{?}%{Io}%{;}%{;})" \
298 ".%s (%{?}%{?}%{*Ac}%{:}pptr()%{;}, %d" \
302 "%d%{?}, %{Iw}%{?}, %{Io}%{;}" \
303 "%{:}%{?}, %{Io}%{;}%{;}" \
312 0 != pfid->tname_, 'w' == *pfid->cname_, 0 != pfid->tname_, \
313 pfid->cname_, 0 != pfid->tname_, pfid->tname_, \
314 0 != str, int (sizeof *wstr), wstr, -1 < mode, mode, -1 < mode, mode, \
315 pfid->fname_, pfid->vfun_ == VFun::xsputn, 0 != pfid->strarg_, \
316 int (sizeof *warg), warg, arg0, \
318 IGN != arg0, arg_int, \
319 arg0, VFun::seekoff == pfid->vfun_, arg1, IGN != arg2, arg2, \
322 const int_type not_eof = Traits::not_eof (arg_int);
324 int success = ret == (
NOT_EOF == ret_expect ? int (not_eof) : ret_expect);
334 CALLFMT " == %{?}not EOF%{:}%{#lc}%{;}, got %{#lc}",
339 if (
IGN != pback_expect)
341 CALLFMT ": putback positions (gptr - eback) == %d, got %d"
342 "%{?}: gptr = NULL%{;}",
347 if (
IGN != read_expect)
349 CALLFMT ": read positions (egptr - gptr) == %d, got %d: "
350 "gptr = %{?}NULL%{:}eback + %td%{;}",
355 if (
IGN != write_expect) {
358 success = -1 < write_expect ?
359 write_expect <= write_pos : 0 == write_pos;
362 CALLFMT ": write positions (epptr - pptr) "
363 "%{?}==%{:}>=%{;} %d, got %d: "
364 "pptr = %{?}NULL%{:}pbase + %td%{;}",
365 CALLARGS, 1 < write_expect, write_expect, write_pos,
373 const std::size_t xmatch =
377 CALLFMT ": put area mismatch (pbase + %zu)",
400#define TEST(charT, Traits) \
401 test_virtual (charT (), Traits (), pfid, line, \
402 str, str_len, mode, gbump, \
403 arg0, arg1, arg2, ret_expect, \
404 pback_expect, read_expect, write_expect)
406 static const char*
const fnames[] = {
407 "xsputn",
"pbackfail",
"overflow",
"underflow",
"seekoff",
"seekpos"
411 rw_note (0, 0, __LINE__,
"test on line %d disabled",
line);
419 TEST (
char, std::char_traits<char>);
420#ifndef _RWSTD_NO_WCHAR_T
422 TEST (
wchar_t, std::char_traits<wchar_t>);
429#ifndef _RWSTD_NO_WCHAR_T
442const int in = std::ios::in;
443const int out = std::ios::out;
444const int ate = std::ios::ate;
446const int cur = std::ios::cur;
447const int end = std::ios::end;
449static int rw_opt_max_size = 1024;
454test_xsputn (
VFun *pfid)
456 rw_info (0, 0, 0,
"basic_stringbuf<%s%{?}, %s%{;}>::xsputn"
457 "(const char_type*, streamsize)",
463#define TEST(str, mode, gbump, sarg, result, pback, read, write) \
464 pfid->strarg_ = sarg; \
465 test_virtual (pfid, __LINE__, str, sizeof str - 1, mode, \
466 gbump, int (sizeof sarg - 1), IGN, IGN, result, \
479 TEST (0, 0, 0,
"", 0, 0, 0, -1);
480 TEST (0, 0, 0,
"a", 0, 0, 0, -1);
481 TEST (0,
in, 0,
"a", 0, 0, 0, -1);
513#define TEST(str, mode, len, result, seq, read) \
514 pfid->strarg_ = 0; pfid->sequence_ = seq; \
515 test_virtual (pfid, __LINE__, str, sizeof str - 1, mode, \
516 0, len, IGN, IGN, result, \
529 TEST (
"a@500b",
in |
out |
ate, 11, 11,
"a@500ba@11", 512);
530 TEST (
"a@500b",
in |
out |
ate, 12, 12,
"a@500ba@12", 513);
531 TEST (
"a@500b",
in |
out |
ate, 13, 13,
"a@500ba@13", 514);
532 TEST (
"a@500b",
in |
out |
ate, 500, 500,
"a@500ba@500", 1001);
533 TEST (
"a@500b",
in |
out |
ate, 501, 501,
"a@500ba@500b", 1002);
534 TEST (
"a@1022b",
in |
out |
ate, 1, 1,
"a@1022ba", 1024);
535 TEST (
"a@1023b",
in |
out |
ate, 1, 1,
"a@1023ba", 1025);
540#define TEST(len, mode, gbump, arg_len, result, pback, read, write) \
541 pfid->strarg_ = long_string + (sizeof long_string - 1 - len), \
542 test_virtual (pfid, __LINE__, pfid->strarg_, \
543 len, mode, gbump, arg_len, IGN, IGN, \
544 result, pback, read, write)
547#define CAP stringbuf_capacity
550 stringbuf_capacity = -1;
582 for (
int i = 0;
i != rw_opt_max_size; ++
i) {
594test_pbackfail (
VFun *pfid)
596 rw_info (0, 0, 0,
"basic_stringbuf<%s%{?}, %s%{;}>::pbackfail(int_type)",
602#define TEST(str, mode, gbump, arg, result, pback, read, write) \
603 test_virtual (pfid, __LINE__, str, sizeof str - 1, mode, \
604 gbump, arg, IGN, IGN, result, pback, read, write)
638 TEST (0, 0, 0,
'c',
EOF, 0, 0, -1);
647 TEST (
"a", 0, 0,
'c',
EOF, 0, 0, -1);
650 TEST (
"a",
in, 1,
'a',
'a', 0, 1, -1);
656 TEST (
"abc",
in, 3,
'c',
'c', 2, 1, -1);
667test_overflow (
VFun *pfid)
669 rw_info (0, 0, 0,
"basic_stringbuf<%s%{?}, %s%{;}>::overflow(int_type)",
675#define TEST(str, mode, gbump, arg, result, pback, read, write) \
676 test_virtual (pfid, __LINE__, str, sizeof str - 1, mode, gbump, \
677 arg, IGN, IGN, result, pback, read, write);
716 TEST (0, 0, 0,
'c',
EOF, 0, 0, -1);
725 TEST (
"", 0, 0,
'c',
EOF, 0, 0, -1);
730 TEST (
"a", 0, 0,
'c',
EOF, 0, 0, -1);
739 TEST (
"ab", 0, 0,
'c',
EOF, 0, 0, -1);
770test_underflow (
VFun *pfid)
772 rw_info (0, 0, 0,
"basic_stringbuf<%s%{?}, %s%{;}>::underflow()",
778#define TEST(str, mode, gbump, result, pback, read, write) \
779 test_virtual (pfid, __LINE__, str, sizeof str - 1, mode, gbump, \
780 IGN, IGN, IGN, result, pback, read, write);
810 TEST (
"", 0, 0,
EOF, 0, 0, -1);
816 TEST (
"abc", 0, 0,
EOF, 0, 0, -1);
817 TEST (
"abc",
in, 0,
'a', 0, 3, -1);
818 TEST (
"abc",
in, 1,
'b', 1, 2, -1);
819 TEST (
"abc",
in, 2,
'c', 2, 1, -1);
837 TEST (
"a$c",
in, 0,
'a', 0, 3, -1);
845test_seek (
VFun *pfid)
851#define TEST(str, mode, gbump, off, which, res, pback, read, write) \
852 test_virtual (pfid, __LINE__, str, sizeof str - 1, mode, gbump, \
853 off, std::ios::beg, which, res, pback, read, write)
918 TEST (0, 0, 0, 0, 0,
NPOS, 0, 0, -1);
925 TEST (0, 0, 0, 0, 0,
NPOS, 0, 0, -1);
927 TEST (
"abc", 0, 0, 0, 0,
NPOS, 0, 0, -1);
928 TEST (
"abc", 0, 0, 1, 0,
NPOS, 0, 0, -1);
929 TEST (
"abc", 0, 0, -1, 0,
NPOS, 0, 0, -1);
932 TEST (
"abc",
in, 0, 0,
in, 0, 0, 3, -1);
933 TEST (
"abc",
in, 0, 1,
in, 1, 1, 2, -1);
934 TEST (
"abc",
in, 0, 2,
in, 2, 2, 1, -1);
935 TEST (
"abc",
in, 0, 3,
in, 3, 3, 0, -1);
939 TEST (
"abc",
in, 1, 0,
in, 0, 0, 3, -1);
940 TEST (
"abc",
in, 1, 1,
in, 1, 1, 2, -1);
941 TEST (
"abc",
in, 1, 2,
in, 2, 2, 1, -1);
942 TEST (
"abc",
in, 1, 3,
in, 3, 3, 0, -1);
946 TEST (
"abc",
in, 2, 0,
in, 0, 0, 3, -1);
947 TEST (
"abc",
in, 2, 1,
in, 1, 1, 2, -1);
948 TEST (
"abc",
in, 2, 2,
in, 2, 2, 1, -1);
949 TEST (
"abc",
in, 2, 3,
in, 3, 3, 0, -1);
972test_seekoff (
VFun *pfid)
974 rw_info (0, 0, 0,
"basic_stringbuf<%s%{?}, %s%{;}>::seekoff(off_type, "
975 "ios_base::seekdir, ios_base::openmode)",
983#define TEST(str, mode, gbump, off, way, which, res, pback, read, write) \
984 test_virtual (pfid, __LINE__, str, sizeof str - 1, mode, gbump, \
985 off, way, which, res, pback, read, write)
1088test_seekpos (
VFun *pfid)
1090 rw_info (0, 0, 0,
"basic_stringbuf<%s%{?}, %s%{;}>::seekpos(pos_type, "
1091 "ios_base::openmode)",
1101static int rw_opt_no_xsputn;
1102static int rw_opt_no_pbackfail;
1103static int rw_opt_no_overflow;
1104static int rw_opt_no_underflow;
1105static int rw_opt_no_seekoff;
1106static int rw_opt_no_seekpos;
1107static int rw_opt_no_seek;
1108static int rw_opt_no_char_traits;
1109static int rw_opt_no_user_traits;
1115#define TEST(function) \
1116 if (rw_opt_no_ ## function) \
1117 rw_note (1 < rw_opt_no_ ## function++, 0, 0, \
1118 "%s test disabled", #function); \
1120 test_ ## function (pfid)
1122 if (pfid->
tname_ && rw_opt_no_user_traits) {
1123 rw_note (1 < rw_opt_no_user_traits++, 0, 0,
1124 "user defined traits test disabled");
1126 else if (!pfid->
tname_ && rw_opt_no_char_traits) {
1127 rw_note (1 < rw_opt_no_char_traits++, 0, 0,
1128 "char_traits test disabled");
1145 if (
'\0' == long_string [0]) {
1147 for (std::size_t
i = 0;
i !=
sizeof long_string - 1; ++
i)
1148 long_string [
i] =
'x';
1151 if (rw_opt_no_seek) {
1152 rw_opt_no_seekoff = 1;
1153 rw_opt_no_seekpos = 1;
1165 fid.tname_ =
"UserTraits";
1171 rw_note (0, 0, 0,
"char tests disabled");
1181 fid.tname_ =
"UserTraits";
1187 rw_note (0, 0, 0,
"char tests disabled");
1196 return rw_test (argc, argv, __FILE__,
1197 "lib.stringbuf.virtuals",
1207 "|-no-char_traits# "
1208 "|-no-user_traits# "
1209 "|-max_buf_size#0-*",
1211 &rw_opt_no_pbackfail,
1212 &rw_opt_no_overflow,
1213 &rw_opt_no_underflow,
1217 &rw_opt_no_char_traits,
1218 &rw_opt_no_user_traits,
1219 int (
sizeof long_string) - 1,
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
const char *const fnames[]
std::char_traits< S > Traits
void test_virtual(charT, Traits, const VFun *pfid, int line, const char *str, std::size_t, int mode, int gbump, int arg0, int arg1, int arg2, int ret_expect, int pback_expect, int read_expect, int write_expect)
#define TEST(charT, Traits)
_TEST_EXPORT char * rw_expand(char *, const char *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX, _RWSTD_SIZE_T *=0)
_TEST_EXPORT _RWSTD_SIZE_T rw_match(const char *, const char *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX)
_TEST_EXPORT int rw_enabled(const char *name)
_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 *,...)
static int_type not_eof(int_type c)
std::char_traits< charT > Base
pos_type Seekpos(pos_type pos, std::ios_base::openmode which)
pos_type Seekpos(pos_type pos)
char_type * Egptr() const
pos_type Seekoff(off_type off, std::ios_base::seekdir way, std::ios_base::openmode which)
int_type Overflow(int_type c)
char_type * Eback() const
char_type * Pbase() const
char_type * Epptr() const
pos_type Seekoff(off_type off, std::ios_base::seekdir way)
int_type Pbackfail(int_type c)
Base::char_type char_type
static int capacity(int n)
std::basic_stringbuf< charT > Base
VFun(charT cid, const char *cname, Traits tid, const char *tname)