44static const char*
const exceptions[] = {
45 "unknown exception",
"ios_base::failure",
"bad_alloc",
"exception"
51#define Good std::ios_base::goodbit
52#define Eof std::ios_base::eofbit
53#define Fail std::ios_base::failbit
54#define Bad std::ios_base::badbit
55#define NotGood (Eof | Fail | Bad)
57#define Skipws std::ios_base::skipws
58#define Left std::ios_base::left
59#define Right std::ios_base::right
61#define WHITESPACE " \f\n\r\t\v"
80extractor_test_cases [] = {
83#define TEST(str, arg, width, flags, state, res, res_width, res_st, bthrow) { \
84 __LINE__, width, flags, state, res_st, res_width, \
85 str, sizeof (str) - 1, arg, sizeof (arg) - 1, \
86 res, sizeof (res) - 1, bthrow \
117 TEST (str, "", 0, 0, Eof, str, 0, Eof, 0), \
118 TEST (str, "", 1, 0, Fail, str, 1, Fail, 0), \
119 TEST (str, "", 2, 0, Bad, str, 2, Bad, 0), \
120 TEST (str, "", 3, Skipws, Eof, str, 3, Eof, 0), \
121 TEST (str, "", 4, Skipws, Fail, str, 4, Fail, 0), \
122 TEST (str, "", 5, Skipws, Bad, str, 5, Bad, 0), \
123 TEST (str, "", 6, Skipws, Good, str, 6, Eof | Fail, 0), \
124 TEST (str, WHITESPACE, 7, 0, Eof, str, 7, Eof, 0), \
125 TEST (str, WHITESPACE, 8, 0, Fail, str, 8, Fail, 0), \
126 TEST (str, WHITESPACE, 9, 0, Bad, str, 9, Bad, 0), \
127 TEST (str, WHITESPACE, 10, Skipws, Eof, str, 10, Eof, 0), \
128 TEST (str, WHITESPACE, 11, Skipws, Fail, str, 11, Fail, 0), \
129 TEST (str, WHITESPACE, 12, Skipws, Bad, str, 12, Bad, 0), \
130 TEST (str, WHITESPACE, 13, Skipws, Good, str, 13, Eof | Fail, 0), \
131 TEST (str, "", 14, Skipws, NotGood, str, 14, Eof | Fail, 1), \
132 TEST (str, WHITESPACE, 15, Skipws, NotGood, str, 15, Eof | Fail, 1)
145 TEST1 (
"a<U0>b<U0>@2c"),
146 TEST1 (
"<U0>ab<U0>@2c"),
179 TEST (str, "", 0, 0, Good, "", 0 , Eof | Fail, 0), \
180 TEST (str, "", 10, 0, Good, "", 0 , Eof | Fail, 0), \
181 TEST (str, WHITESPACE, 0, 0, Good, "", 0 , Fail, 0), \
182 TEST (str, WHITESPACE, 2, 0, Good, "", 0 , Fail, 0), \
183 TEST (str, WHITESPACE, 20, 0, Good, "", 0 , Fail, 0), \
184 TEST (str, WHITESPACE "abc", 0, 0, Good, "", 0 , Fail, 0), \
185 TEST (str, WHITESPACE "abc", 2, 0, Good, "", 0 , Fail, 0), \
186 TEST (str, WHITESPACE "abc", 10, 0, Good, "", 0 , Fail, 0), \
187 TEST (str, WHITESPACE "abc\ndef", 0, 0, Good, "", 0 , Fail, 0), \
188 TEST (str, WHITESPACE "abc\ndef", 3, 0, Good, "", 0 , Fail, 0), \
189 TEST (str, WHITESPACE "abc\ndef", 30, 0, Good, "", 0 , Fail, 0), \
190 TEST (str, WHITESPACE "<U0>@3", 0, 0, Good, "", 0 , Fail, 0), \
191 TEST (str, WHITESPACE "<U0>@3", 2, 0, Good, "", 0 , Fail, 0), \
192 TEST (str, WHITESPACE "<U0>@3", 10, 0, Good, "", 0 , Fail, 0), \
193 TEST (str, "", 0, 0, NotGood, "", 0 , Eof | Fail, 1), \
194 TEST (str, "", 10, 0, NotGood, "", 0 , Eof | Fail, 1), \
195 TEST (str, WHITESPACE, 0, 0, NotGood, "", 0 , Fail, 1), \
196 TEST (str, WHITESPACE, 2, 0, NotGood, "", 0 , Fail, 1), \
197 TEST (str, WHITESPACE, 20, 0, NotGood, "", 0 , Fail, 1), \
198 TEST (str, WHITESPACE "abc", 0, 0, NotGood, "", 0 , Fail, 1), \
199 TEST (str, WHITESPACE "abc", 2, 0, NotGood, "", 0 , Fail, 1), \
200 TEST (str, WHITESPACE "abc", 10, 0, NotGood, "", 0 , Fail, 1), \
201 TEST (str, WHITESPACE "abc\ndef", 0, 0, NotGood, "", 0 , Fail, 1), \
202 TEST (str, WHITESPACE "abc\ndef", 3, 0, NotGood, "", 0 , Fail, 1), \
203 TEST (str, WHITESPACE "abc\ndef", 30, 0, NotGood, "", 0 , Fail, 1), \
204 TEST (str, WHITESPACE "<U0>@3", 0, 0, NotGood, "", 0 , Fail, 1), \
205 TEST (str, WHITESPACE "<U0>@3", 2, 0, NotGood, "", 0 , Fail, 1), \
206 TEST (str, WHITESPACE "<U0>@3", 10, 0, NotGood, "", 0 , Fail, 1)
219 TEST2 (
"a<U0>b<U0>@2c"),
220 TEST2 (
"<U0>ab<U0>@2c"),
254#define TEST3(arg, width, flags, res) \
255 TEST ("", arg, width, flags, Good, res, 0, -1, 0), \
256 TEST ("ab", arg, width, flags, Good, res, 0, -1, 0), \
257 TEST ("abc", arg, width, flags, Good, res, 0, -1, 0), \
258 TEST ("<U0>", arg, width, flags, Good, res, 0, -1, 0), \
259 TEST ("<U0>@2ab", arg, width, flags, Good, res, 0, -1, 0), \
260 TEST ("a<U0>@2b", arg, width, flags, Good, res, 0, -1, 0), \
261 TEST ("ab<U0>@2", arg, width, flags, Good, res, 0, -1, 0), \
262 TEST ("a<U0>b<U0>@2c", arg, width, flags, Good, res, 0, -1, 0), \
263 TEST ("<U0>ab<U0>@2c", arg, width, flags, Good, res, 0, -1, 0), \
264 TEST ("x@4096", arg, width, flags, Good, res, 0, -1, 0), \
265 TEST ("", arg, width, flags, NotGood, res, 0, -1, 1), \
266 TEST ("ab", arg, width, flags, NotGood, res, 0, -1, 1), \
267 TEST ("abc", arg, width, flags, NotGood, res, 0, -1, 1), \
268 TEST ("<U0>", arg, width, flags, NotGood, res, 0, -1, 1), \
269 TEST ("<U0>@2ab", arg, width, flags, NotGood, res, 0, -1, 1), \
270 TEST ("a<U0>@2b", arg, width, flags, NotGood, res, 0, -1, 1), \
271 TEST ("ab<U0>@2", arg, width, flags, NotGood, res, 0, -1, 1), \
272 TEST ("a<U0>b<U0>@2c", arg, width, flags, NotGood, res, 0, -1, 1), \
273 TEST ("<U0>ab<U0>@2c", arg, width, flags, NotGood, res, 0, -1, 1), \
274 TEST ("x@4096", arg, width, flags, NotGood, res, 0, -1, 1)
283 TEST3 (
"a!bc", 1, 0,
"a" ),
284 TEST3 (
"a!bc", 2, 0,
"a!" ),
285 TEST3 (
"a!bc", 10, 0,
"a!bc"),
286 TEST3 (
"ab!c ", 10, 0,
"ab!c"),
287 TEST3 (
"ab!c\f", 10, 0,
"ab!c"),
288 TEST3 (
"ab!c\n", 10, 0,
"ab!c"),
289 TEST3 (
"ab!c\r", 10, 0,
"ab!c"),
290 TEST3 (
"ab!c\t", 10, 0,
"ab!c"),
291 TEST3 (
"ab!c\v", 10, 0,
"ab!c"),
331getline_test_cases [] = {
334#define TEST(str, arg, width, flags, state, res, res_width, res_st, bthrow) { \
335 __LINE__, width, flags, state, res_st, res_width, \
336 str, sizeof (str) - 1, arg, sizeof (arg) - 1, \
337 res, sizeof (res) - 1, bthrow \
366 TEST (str, "", 0, 0, Eof, str, 0, Eof, 0), \
367 TEST (str, "", 1, 0, Fail, str, 0, Fail, 0), \
368 TEST (str, "", 2, 0, Bad, str, 0, Bad, 0), \
369 TEST (str, "", 3, Skipws, Eof, str, 0, Eof, 0), \
370 TEST (str, "", 4, Skipws, Fail, str, 0, Fail, 0), \
371 TEST (str, "", 5, Skipws, Bad, str, 0, Bad, 0), \
372 TEST (str, WHITESPACE, 7, 0, Eof, str, 0, Eof, 0), \
373 TEST (str, WHITESPACE, 8, 0, Fail, str, 0, Fail, 0), \
374 TEST (str, WHITESPACE, 9, 0, Bad, str, 0, Bad, 0), \
375 TEST (str, WHITESPACE, 10, Skipws, Eof, str, 0, Eof, 0), \
376 TEST (str, WHITESPACE, 11, Skipws, Fail, str, 0, Fail, 0), \
377 TEST (str, WHITESPACE, 12, Skipws, Bad, str, 0, Bad, 0), \
378 TEST (str, "abc", 13, 0, Eof, str, 0, Eof, 0), \
379 TEST (str, "x@4096", 14, 0, Fail, str, 0, Fail, 0), \
380 TEST (str, "<U0>abc<U0>", 15, 0, Bad, str, 0, Bad, 0), \
381 TEST (str, "abc\ndef", 16, Skipws, Eof, str, 0, Eof, 0), \
382 TEST (str, " \tabc", 17, Skipws, Fail, str, 0, Fail, 0), \
383 TEST (str, "\n\n<U0>\n", 18, Skipws, Bad, str, 0, Bad, 0)
396 TEST1 (
"a<U0>b<U0>@2c"),
397 TEST1 (
"<U0>ab<U0>@2c"),
429 TEST (str, "", 0, Skipws, Good, "", 0, Eof | Fail, 0), \
430 TEST (str, "", 10, 0, Good, "", 0, Eof | Fail, 0), \
431 TEST (str, "\n", 0, Skipws, Good, "", 0, Good, 0), \
432 TEST (str, "\n", 2, 0, Good, "", 0, Good, 0), \
433 TEST (str, "\nabc", 0, Skipws, Good, "", 0, Good, 0), \
434 TEST (str, "\nabc", 2, 0, Good, "", 0, Good, 0), \
435 TEST (str, "\nabc\ndef", 0, Skipws, Good, "", 0, Good, 0), \
436 TEST (str, "\nabc\ndef", 3, 0, Good, "", 0, Good, 0), \
437 TEST (str, "\n<U0>@3", 0, Skipws, Good, "", 0, Good, 0), \
438 TEST (str, "\n<U0>@3", 2, 0, Good, "", 0, Good, 0), \
439 TEST (str, "", 0, Skipws, NotGood, "", 0, Eof | Fail, 1), \
440 TEST (str, "", 10, 0, NotGood, "", 0, Eof | Fail, 1), \
441 TEST (str, "\n", 0, Skipws, NotGood, "", 0, Good, 1), \
442 TEST (str, "\n", 2, 0, NotGood, "", 0, Good, 1), \
443 TEST (str, "\nabc", 0, Skipws, NotGood, "", 0, Good, 1), \
444 TEST (str, "\nabc", 2, 0, NotGood, "", 0, Good, 1), \
445 TEST (str, "\nabc\ndef", 0, Skipws, NotGood, "", 0, Good, 1), \
446 TEST (str, "\nabc\ndef", 3, 0, NotGood, "", 0, Good, 1), \
447 TEST (str, "\n<U0>@3", 0, Skipws, NotGood, "", 0, Good, 1), \
448 TEST (str, "\n<U0>@3", 2, 0, NotGood, "", 0, Good, 1)
461 TEST2 (
"a<U0>b<U0>@2c"),
462 TEST2 (
"<U0>ab<U0>@2c"),
493#define TEST3(arg, res) \
494 TEST ("", arg, 0, Skipws, Good, res, 0, -1, 0), \
495 TEST ("ab", arg, 1, 0, Good, res, 0, -1, 0), \
496 TEST ("abc", arg, 2, Skipws, Good, res, 0, -1, 0), \
497 TEST ("<U0>", arg, 3, 0, Good, res, 0, -1, 0), \
498 TEST ("<U0>@2ab", arg, 4, Skipws, Good, res, 0, -1, 0), \
499 TEST ("a<U0>@2b", arg, 5, 0, Good, res, 0, -1, 0), \
500 TEST ("ab<U0>@2", arg, 6, Skipws, Good, res, 0, -1, 0), \
501 TEST ("a<U0>b<U0>@2c", arg, 7, 0, Good, res, 0, -1, 0), \
502 TEST ("<U0>ab<U0>@2c", arg, 8, Skipws, Good, res, 0, -1, 0), \
503 TEST ("x@4096", arg, 9, 0, Good, res, 0, -1, 0), \
504 TEST ("", arg, 10, Skipws, NotGood, res, 0, -1, 1), \
505 TEST ("ab", arg, 11, 0, NotGood, res, 0, -1, 1), \
506 TEST ("abc", arg, 12, Skipws, NotGood, res, 0, -1, 1), \
507 TEST ("<U0>", arg, 13, 0, NotGood, res, 0, -1, 1), \
508 TEST ("<U0>@2ab", arg, 14, Skipws, NotGood, res, 0, -1, 1), \
509 TEST ("a<U0>@2b", arg, 15, 0, NotGood, res, 0, -1, 1), \
510 TEST ("ab<U0>@2", arg, 16, Skipws, NotGood, res, 0, -1, 1), \
511 TEST ("a<U0>b<U0>@2c", arg, 17, 0, NotGood, res, 0, -1, 1), \
512 TEST ("<U0>ab<U0>@2c", arg, 18, Skipws, NotGood, res, 0, -1, 1), \
513 TEST ("x@4096", arg, 19, 0, NotGood, res, 0, -1, 1)
520 TEST3 (
"ab!c",
"ab!c" ),
521 TEST3 (
"a!b\nc",
"a!b" ),
522 TEST3 (
"a\n!bc",
"a" ),
523 TEST3 (
" !\t\n",
" !\t" ),
524 TEST3 (
" \f\r\t\v\n",
" \f\r\t\v" ),
525 TEST3 (
" \f\r\n\t\v\n",
" \f\r" ),
526 TEST3 (
"<U0>a<U0>b<U0>\n<U0>@2",
"<U0>a<U0>b<U0>"),
527 TEST3 (
"<U0>@7",
"<U0>@7" ),
528 TEST3 (
"x@4096",
"x@4096" ),
529 TEST3 (
"x@4096\nx@4096",
"x@4096" )
549getline_val_test_cases [] = {
552#define TEST(str, arg, width, flags, state, res, res_width, res_st, bthrow) { \
553 __LINE__, width, flags, state, res_st, res_width, \
554 str, sizeof (str) - 1, arg, sizeof (arg) - 1, \
555 res, sizeof (res) - 1, bthrow \
584 TEST (str, "", 0, 0, Eof, str, '\n', Eof, 0), \
585 TEST (str, "", 1, 0, Fail, str, '\0', Fail, 0), \
586 TEST (str, "", 2, 0, Bad, str, '\r', Bad, 0), \
587 TEST (str, "", 3, Skipws, Eof, str, '\a', Eof, 0), \
588 TEST (str, "", 4, Skipws, Fail, str, '\b', Fail, 0), \
589 TEST (str, "", 5, Skipws, Bad, str, '\t', Bad, 0), \
590 TEST (str, WHITESPACE, 7, 0, Eof, str, '\v', Eof, 0), \
591 TEST (str, WHITESPACE, 8, 0, Fail, str, 'a', Fail, 0), \
592 TEST (str, WHITESPACE, 9, 0, Bad, str, ' ', Bad, 0), \
593 TEST (str, WHITESPACE, 10, Skipws, Eof, str, '1', Eof, 0), \
594 TEST (str, WHITESPACE, 11, Skipws, Fail, str, '5', Fail, 0), \
595 TEST (str, WHITESPACE, 12, Skipws, Bad, str, 'w', Bad, 0), \
596 TEST (str, "abc", 13, 0, Eof, str, 'b', Eof, 0), \
597 TEST (str, "x@4096", 14, 0, Fail, str, 'x', Fail, 0), \
598 TEST (str, "<U0>abc<U0>", 15, 0, Bad, str, 'c', Bad, 0), \
599 TEST (str, "abc\ndef", 16, Skipws, Eof, str, 'e', Eof, 0), \
600 TEST (str, " \tabc", 17, Skipws, Fail, str, '\t', Fail, 0), \
601 TEST (str, "\n\n<U0>\n", 18, Skipws, Bad, str, '\0', Bad, 0)
614 TEST1 (
"a<U0>b<U0>@2c"),
615 TEST1 (
"<U0>ab<U0>@2c"),
647 TEST (str, "", 0, Skipws, Good, "", '\a', Eof | Fail, 0), \
648 TEST (str, "", 10, 0, Good, "", '\0', Eof | Fail, 0), \
649 TEST (str, "<U0>", 0, Skipws, Good, "", '\0', Good, 0), \
650 TEST (str, "\n", 2, 0, Good, "", '\n', Good, 0), \
651 TEST (str, "\rabc", 0, Skipws, Good, "", '\r', Good, 0), \
652 TEST (str, "abc", 2, 0, Good, "", 'a', Good, 0), \
653 TEST (str, "\babc\ndef", 0, Skipws, Good, "", '\b', Good, 0), \
654 TEST (str, "\tabc\ndef", 3, 0, Good, "", '\t', Good, 0), \
655 TEST (str, "\v<U0>@3", 0, Skipws, Good, "", '\v', Good, 0), \
656 TEST (str, " <U0>@3", 2, 0, Good, "", ' ', Good, 0), \
657 TEST (str, "", 0, Skipws, NotGood, "", '\a', Eof | Fail, 1), \
658 TEST (str, "", 10, 0, NotGood, "", '\0', Eof | Fail, 1), \
659 TEST (str, "<U0>", 0, Skipws, NotGood, "", '\0', Good, 1), \
660 TEST (str, "\n", 2, 0, NotGood, "", '\n', Good, 1), \
661 TEST (str, "\rabc", 0, Skipws, NotGood, "", '\r', Good, 1), \
662 TEST (str, "abc", 2, 0, NotGood, "", 'a', Good, 1), \
663 TEST (str, "\babc\ndef", 0, Skipws, NotGood, "", '\b', Good, 1), \
664 TEST (str, "\tabc\ndef", 3, 0, NotGood, "", '\t', Good, 1), \
665 TEST (str, "\v<U0>@3", 0, Skipws, NotGood, "", '\v', Good, 1), \
666 TEST (str, " <U0>@3", 2, 0, NotGood, "", ' ', Good, 1)
679 TEST2 (
"a<U0>b<U0>@2c"),
680 TEST2 (
"<U0>ab<U0>@2c"),
711#define TEST3(arg, delim, res) \
712 TEST ("", arg, 0, Skipws, Good, res, delim, -1, 0), \
713 TEST ("ab", arg, 1, 0, Good, res, delim, -1, 0), \
714 TEST ("abc", arg, 2, Skipws, Good, res, delim, -1, 0), \
715 TEST ("<U0>", arg, 3, 0, Good, res, delim, -1, 0), \
716 TEST ("<U0>@2ab", arg, 4, Skipws, Good, res, delim, -1, 0), \
717 TEST ("a<U0>@2b", arg, 5, 0, Good, res, delim, -1, 0), \
718 TEST ("ab<U0>@2", arg, 6, Skipws, Good, res, delim, -1, 0), \
719 TEST ("a<U0>b<U0>@2c", arg, 7, 0, Good, res, delim, -1, 0), \
720 TEST ("<U0>ab<U0>@2c", arg, 8, Skipws, Good, res, delim, -1, 0), \
721 TEST ("x@4096", arg, 9, 0, Good, res, delim, -1, 0), \
722 TEST ("", arg, 10, Skipws, NotGood, res, delim, -1, 1), \
723 TEST ("ab", arg, 11, 0, NotGood, res, delim, -1, 1), \
724 TEST ("abc", arg, 12, Skipws, NotGood, res, delim, -1, 1), \
725 TEST ("<U0>", arg, 13, 0, NotGood, res, delim, -1, 1), \
726 TEST ("<U0>@2ab", arg, 14, Skipws, NotGood, res, delim, -1, 1), \
727 TEST ("a<U0>@2b", arg, 15, 0, NotGood, res, delim, -1, 1), \
728 TEST ("ab<U0>@2", arg, 16, Skipws, NotGood, res, delim, -1, 1), \
729 TEST ("a<U0>b<U0>@2c", arg, 17, 0, NotGood, res, delim, -1, 1), \
730 TEST ("<U0>ab<U0>@2c", arg, 18, Skipws, NotGood, res, delim, -1, 1), \
731 TEST ("x@4096", arg, 19, 0, NotGood, res, delim, -1, 1)
739 TEST3 (
"ab!c",
'\t',
"ab!c" ),
740 TEST3 (
"a!b<U0>c",
'\0',
"a!b" ),
741 TEST3 (
"a\n!bc",
'b',
"a\n!" ),
742 TEST3 (
" \t\n",
'\n',
" \t" ),
743 TEST3 (
" \f\r\t\v\n",
'\v',
" \f\r\t" ),
744 TEST3 (
" \f\r\n\t\v\n",
'\r',
" \f" ),
745 TEST3 (
"<U0>a<U0>b<U0>\n<U0>@2",
'b',
"<U0>a<U0>"),
746 TEST3 (
"<U0>@7",
'1',
"<U0>@7" ),
747 TEST3 (
"x@4096",
' ',
"x@4096" ),
748 TEST3 (
"x@4096yx@4096",
'y',
"x@4096" )
768inserter_test_cases [] = {
771#define TEST(str, arg, width, flags, state, res, res_width, res_st, bthrow) { \
772 __LINE__, width, flags, state, res_st, res_width, \
773 str, sizeof (str) - 1, 0, arg, res, sizeof (res) - 1, bthrow \
802 TEST (str, 0, 0, 0, Eof, "", 0, Eof, 0), \
803 TEST (str, 0, 1, 0, Fail, "", 1, Fail, 0), \
804 TEST (str, 0, 2, 0, Bad, "", 2, Bad, 0)
817 TEST1 (
"a<U0>b<U0>@2c"),
818 TEST1 (
"<U0>ab<U0>@2c"),
848#define TEST2(str, arg, width, flags, res, res_width, res_st) \
849 TEST (str, arg, width, flags, Good, res, res_width, res_st, 0), \
850 TEST (str, arg, width, flags, NotGood, res, res_width, res_st, 1)
872 TEST2 (
"", 5, 10, 0,
" @5", 0,
Bad ),
876 TEST2 (
" @10", 20, 10, 0,
" @10", 0,
Good),
880 TEST2 (
"abc def", 20, 0, 0,
"abc def", 0,
Good),
884 TEST2 (
"abc def", 5, 0, 0,
"abc d", 0,
Bad ),
888 TEST2 (
"abc def", 20, 5, 0,
"abc def", 0,
Good),
892 TEST2 (
"abc def", 20, 10, 0,
" abc def", 0,
Good),
896 TEST2 (
"<U0>", 20, 10, 0,
" @9<U0>", 0,
Good),
900 TEST2 (
"<U0>ab<U0>@2c", 20, 10, 0,
" @4<U0>ab<U0>@2c", 0,
Good),
901 TEST2 (
"<U0>ab<U0>@2c", 20, 10,
Right,
" @4<U0>ab<U0>@2c", 0,
Good),
902 TEST2 (
"<U0>ab<U0>@2c", 20, 10,
Left,
"<U0>ab<U0>@2c @4", 0,
Good),
904 TEST2 (
"x@4096", 4096, 10, 0,
"x@4096", 0,
Good),
908 TEST2 (
"x@4096", 4097, 4097, 0,
" x@4096", 0,
Good),
915template <
class charT,
class Traits,
class Allocator>
919 typedef std::basic_string <charT, Traits, Allocator>
String;
921 typedef std::basic_ios<charT, Traits> BasicIos;
922 typedef std::basic_istream<charT, Traits> Istream;
923 typedef std::basic_ostream<charT, Traits> Ostream;
925 typedef std::ios_base::fmtflags Fmtflags;
926 typedef std::ios_base::iostate Iostate;
931 bool test_inserter =
func.which_ == StringIds::inserter_ostream_cstr;
939 static const std::size_t BUFSIZE = 256;
941 static char arg_buf [BUFSIZE];
943 std::size_t arg_len = 0;
947 const charT* arg_throw = test_inserter ? tdata.
str_ : tdata.
arg_;
948 const std::size_t arg_throw_len =
951 std::size_t* throw_on =
new std::size_t [arg_throw_len + 1];
952 std::size_t pthrow = 0;
953 for (std::size_t
k = 0;
k < arg_throw_len; ++
k) {
955 throw_on [pthrow++] =
k + 1;
957 throw_on [pthrow] =
NPOS;
966 const Fmtflags
flags = Fmtflags (tcase.
size);
973 std::size_t throw_count [] = { 1, 1, 1 };
974 std::size_t throw_inx = 0;
983 Streambuf& sbuf = test_inserter ? outbuf : inbuf;
985#ifndef _RWSTD_NO_EXCEPTIONS
988 const char* expected = 0;
992 expected = exceptions [1];
994 else if (0 == tcase.
bthrow) {
996 sbuf.throw_when_ [sbuf.memfun_inx (
998 int (throw_on [throw_inx]);
1000 sbuf.throw_when_ [sbuf.memfun_inx (
Xsgetn)] =
1001 int (throw_count [0]);
1002 sbuf.throw_when_ [sbuf.memfun_inx (
Sync)] =
1003 int (throw_count [1]);
1004 sbuf.throw_when_ [sbuf.memfun_inx (
Xsputn)] =
1005 int (throw_count [2]);
1019 Istream is (&inbuf);
1020 Ostream
os (&outbuf);
1024 BasicIos &
strm = test_inserter ? (BasicIos&)
os : (BasicIos&)is;
1027 strm.imbue (std::locale (
strm.getloc (), &ctyp));
1034 const Iostate state = Iostate (tcase.
off2);
1038 strm.exceptions (state);
1048 bool streambuf_threw =
false;
1055 std::ptrdiff_t ret_off = 0;
1058 switch (
func.which_) {
1060 case StringIds::extractor_istream_str:
1061 ret_off = &is - &(is >>
str);
1064 case StringIds::getline_istream_str:
1065 ret_off = &is - &std::getline (is,
str);
1068 case StringIds::getline_istream_str_val: {
1070 ret_off = &is - &std::getline (is,
str, delim);
1074 case StringIds::inserter_ostream_cstr:
1075 ret_off = &
os - &(
os << cstr);
1079 RW_ASSERT (!
"test logic error: unknown io overload");
1083#ifndef _RWSTD_NO_EXCEPTIONS
1085 catch (std::ios_base::failure& ex) {
1088 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
1089 "unexpectedly%{;} caught std::%s(%#s)",
1090 __LINE__, 0 != expected, expected,
caught,
1097 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
1098 "unexpectedly%{;} caught %s",
1099 __LINE__, 0 != expected, expected,
caught);
1104 const std::streamsize ret_width =
strm.width ();
1105 const Iostate ret_state =
strm.rdstate ();
1106 const charT* ret_str =
str.data ();
1107 std::size_t ret_sz =
str.size ();
1109 if (test_inserter) {
1110 ret_str = outbuf.pubpbase ();
1111 ret_sz = outbuf.pubepptr () - ret_str;
1114 streambuf_threw =
None != sbuf.threw_;
1116 if (streambuf_threw) {
1119 if (
Xsgetn == sbuf.threw_)
1121 if (
Sync == sbuf.threw_)
1123 if (
Xsputn == sbuf.threw_)
1128 static const int cwidth =
sizeof (
charT);
1132 bool success = 0 == ret_off;
1134 "line %d. %{$FUNCALL} returned invalid reference, "
1135 "offset is %td", __LINE__, ret_off);
1137 if (!streambuf_threw) {
1140 const std::streamsize width =
1141 func.which_ == StringIds::getline_istream_str
1142 ||
func.which_ == StringIds::getline_istream_str_val
1143#ifndef _RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE
1144 || (
func.which_ == StringIds::inserter_ostream_cstr
1145 && ret_state !=
Good)
1149 success = width == ret_width;
1151 "line %d. %{$FUNCALL}: expected width() == %td, "
1152 "got %td", __LINE__, width, ret_width);
1156 if (0 <= tcase.
size2) {
1159 const Iostate res_state =
1160 streambuf_threw ?
Bad : Iostate (tcase.
size2);
1162 success = res_state ?
1163 (res_state == (ret_state & res_state)) : (0 == ret_state);
1165 "line %d. %{$FUNCALL}: expected rdstate() "
1166 "== %{Is}, got %{Is}",
1167 __LINE__, res_state, ret_state);
1170 if ( !streambuf_threw
1173 std::size_t res_sz = streambuf_threw ?
1174 sbuf.throw_when_ [sbuf.memfun_inx (sbuf.threw_)] - 1 :
1178 success = res_sz == ret_sz;
1180 "line %d. %{$FUNCALL}: expected %{/*.*Gs} with "
1181 "length %zu, got %{/*.*Gs} with length %zu",
1183 cwidth, int (res_sz), tdata.
res_, res_sz,
1184 cwidth, int (ret_sz), ret_str, ret_sz);
1186 if (res_sz == ret_sz) {
1193 success = match == res_sz;
1195 "line %d. %{$FUNCALL}: expected %{/*.*Gs}, "
1196 "got %{/*.*Gs}, difference at off %zu",
1197 __LINE__, cwidth, int (res_sz), tdata.
res_,
1198 cwidth, int (ret_sz), ret_str, match);
1203#ifndef _RWSTD_NO_EXCEPTIONS
1208 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
1209 "unexpectedly%{;} caught std::%s(%#s)",
1210 __LINE__, 0 != expected, expected,
caught, ex.what ());
1215 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
1216 "unexpectedly%{;} caught std::%s(%#s)",
1217 __LINE__, 0 != expected, expected,
caught, ex.what ());
1222 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
1223 "unexpectedly%{;} caught %s",
1224 __LINE__, 0 != expected, expected,
caught);
1232 std::size_t (-1), std::size_t (-1));
1234 if (streambuf_threw && 0 == tcase.
bthrow) {
1239 else if (1 < tcase.
bthrow) {
1241 "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
1242 "%{:}unexpectedly caught %s%{;}",
1254 __LINE__, tcase.
line,
"call");
1276#define TEST(gsig, sig) { \
1277 gsig, sig ## _test_cases, \
1278 sizeof sig ## _test_cases / sizeof *sig ## _test_cases \
1281 TEST (StringIds::extractor_istream_str, extractor),
1283 TEST (StringIds::getline_istream_str, getline),
1284 TEST (StringIds::getline_istream_str_val, getline_val)
1287 const std::size_t test_count =
sizeof tests /
sizeof *tests;
1291 test_io_func_array, tests, test_count);
void test_io(charT *, Traits *, Allocator *, const StringTestCaseData< charT > &tdata)
#define TEST(str, arg, width, flags, state, res, res_width, res_st, bthrow)
#define TEST3(arg, width, flags, res)
std::char_traits< S > Traits
const StringTestCase & tcase_
_TEST_EXPORT void rw_check_leaks(const SharedAlloc *=0, int=0, _RWSTD_SIZE_T=0, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX)
UserChar make_char(char c, UserChar *)
_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_assert(int, const char *, int, const char *,...)
StringState rw_get_string_state(const String &str)
_TEST_EXPORT int rw_run_string_test(int, char **, const char *, const char *, StringTestFunc *, const StringTest *, _RWSTD_SIZE_T)
#define DEFINE_STRING_TEST_FUNCTIONS(fname)
int assert_equal(const StringState &, int, int, const char *) const
Helper class for suppressing move-construction in single-argument array constructors.