40#define Insert(sig) ListIds::insert_ ## sig
42static const char*
const exceptions[] = {
43 "unknown exception",
"bad_alloc",
"exception"
51iter_range_test_cases [] = {
54#define TEST(lst, off, arg, off2, size2, res, bthrow) { \
55 __LINE__, off, -1, off2, size2, -1, lst, sizeof lst - 1, \
56 arg, sizeof arg - 1, res, sizeof res - 1, bthrow \
73 TEST (
"ab", 0,
"c", 0, 1,
"cab", 0),
75 TEST (
"", 0,
"", 0, 0,
"", 0),
76 TEST (
"", 0,
"abc", 1, 1,
"b", 0),
77 TEST (
"", 0,
"<U0>", 0, 1,
"<U0>", 0),
79 TEST (
"<U0>", 0,
"", 0, 0,
"<U0>", 0),
80 TEST (
"<U0>", 1,
"", 0, 0,
"<U0>", 0),
82 TEST (
"abc", 0,
"", 0, 0,
"abc", 0),
83 TEST (
"abc", 1,
"", 0, 0,
"abc", 0),
84 TEST (
"abc", 3,
"", 0, 0,
"abc", 0),
86 TEST (
"<U0>", 0,
"a", 0, 1,
"a<U0>", 0),
87 TEST (
"<U0>", 1,
"a", 0, 1,
"<U0>a", 0),
88 TEST (
"<U0>", 0,
"<U0>@2", 1, 1,
"<U0>@2", 0),
89 TEST (
"<U0>", 1,
"<U0>@2", 0, 2,
"<U0>@3", 0),
91 TEST (
"cde", 0,
"ab", 0, 2,
"abcde", 0),
92 TEST (
"cde", 1,
"ab", 0, 1,
"cade", 0),
93 TEST (
"cde", 3,
"ab", 1, 1,
"cdeb", 0),
95 TEST (
"ab", 0,
"c<U0>e", 0, 3,
"c<U0>eab", 0),
96 TEST (
"ab", 1,
"c<U0>e", 1, 2,
"a<U0>eb", 0),
97 TEST (
"ab", 2,
"c<U0>e", 0, 2,
"abc<U0>", 0),
99 TEST (
"<U0>e<U0>", 1,
"<U0>ab<U0>@2c", 0, 6,
"<U0>@2ab<U0>@2ce<U0>",0),
100 TEST (
"<U0>e<U0>", 1,
"<U0>ab<U0>@2c", 0, 3,
"<U0>@2abe<U0>", 0),
101 TEST (
"a<U0>b<U0>@2c", 3,
"<U0>e<U0>", 0, 3,
"a<U0>b<U0>e<U0>@3c", 0),
102 TEST (
"a<U0>b<U0>@2c", 2,
"<U0>@2e<U0>", 0, 2,
"a<U0>@3b<U0>@2c", 0),
103 TEST (
"<U0>ab<U0>@2c", 0,
"<U0>e<U0>", 2, 1,
"<U0>@2ab<U0>@2c", 0),
104 TEST (
"a<U0>bc<U0>@2", 6,
"<U0>e", 0, 2,
"a<U0>bc<U0>@3e", 0),
106 TEST (
"", 0,
"x@4096", 0, 4096,
"x@4096", 0),
107 TEST (
"x@4096", 0,
"", 0, 0,
"x@4096", 0),
108 TEST (
"a@1000", 0,
"b@1000", 0, 999,
"b@999a@1000", 0),
109 TEST (
"a@1000", 1,
"b@1001", 0, 1000,
"ab@1000a@999", 0),
110 TEST (
"a@1000", 2,
"b@1002", 0, 1001,
"aab@1001a@998", 0),
111 TEST (
"a@1000", 998,
"b@1000", 1, 999,
"a@998b@999aa", 0),
112 TEST (
"a@1000", 999,
"b@1001", 2, 999,
"a@999b@999a", 0),
113 TEST (
"a@1000", 2,
"b@1002", 999, 3,
"aabbba@998", 0),
115 TEST (
"x@10", 1,
"x@118", 0, 118,
"x@128", 0),
116 TEST (
"x@128", 0,
"x@129", 50, 79,
"x@207", 0),
117 TEST (
"x@207", 207,
"x@127", 0, 127,
"x@334", 0),
118 TEST (
"x@207", 128,
"x@207", 10, 127,
"x@334", 0),
119 TEST (
"x@334", 334,
"x@208", 2, 206,
"x@540", 0),
120 TEST (
"x@540", 0,
"x@336", 3, 333,
"x@873", 0),
121 TEST (
"x@539", 538,
"x@873", 0, 873,
"x@1412", 0),
122 TEST (
"x@873", 540,
"x@540", 1, 539,
"x@1412", 0),
123 TEST (
"x@872", 0,
"x@1412", 0, 1412,
"x@2284", 0),
124 TEST (
"x@1411", 1411,
"x@2288", 4, 2284,
"x@3695", 0),
125 TEST (
"x@1411", 872,
"x@3695", 128, 2284,
"x@3695", 0),
126 TEST (
"x@1412", 0,
"x@2284", 0, 2284,
"x@3696", 0),
128 TEST (
"<U0>", 2,
"", 0, 0,
"<U0>", 1),
129 TEST (
"", 0,
"<U0>", 2, 0,
"", 2),
131 TEST (
"a", 2,
"", 0, 0,
"a", 1),
132 TEST (
"", 0,
"a", 2, 0,
"", 2),
134 TEST (
"x@4096", 4106,
"", 0, 0,
"x@4096", 1),
135 TEST (
"", 0,
"x@4096", 4106, 0,
"", 2),
137 TEST (
"last", 4,
"test", 0, 4,
"lasttest", 0)
145iter_size_cref_test_cases [] = {
148#define TEST(lst, off, size, val, res, bthrow) { \
149 __LINE__, off, size, -1, -1, val, lst, sizeof lst - 1, \
150 0, 0, res, sizeof res - 1, bthrow \
166 TEST (
"ab", 0, 1,
'c',
"cab", 0),
168 TEST (
"", 0, 0,
' ',
"", 0),
169 TEST (
"", 0, 1,
'b',
"b", 0),
171 TEST (
"<U0>", 0, 0,
' ',
"<U0>", 0),
172 TEST (
"<U0>", 1, 0,
' ',
"<U0>", 0),
173 TEST (
"", 0, 2,
'\0',
"<U0>@2", 0),
175 TEST (
"<U0>", 0, 1,
'a',
"a<U0>", 0),
176 TEST (
"<U0>", 1, 1,
'a',
"<U0>a", 0),
177 TEST (
"<U0>", 0, 1,
'\0',
"<U0>@2", 0),
178 TEST (
"<U0>", 1, 2,
'\0',
"<U0>@3", 0),
179 TEST (
"<U0>", 1, 0,
'\0',
"<U0>", 0),
181 TEST (
"cde", 0, 2,
'a',
"aacde", 0),
182 TEST (
"cde", 1, 1,
'a',
"cade", 0),
183 TEST (
"cde", 3, 3,
'a',
"cdeaaa", 0),
184 TEST (
"cde", 2, 3,
'a',
"cdaaae", 0),
186 TEST (
"ab", 0, 2,
'\0',
"<U0>@2ab", 0),
187 TEST (
"ab", 1, 1,
'\0',
"a<U0>b", 0),
188 TEST (
"ab", 2, 2,
'\0',
"ab<U0>@2", 0),
190 TEST (
"a<U0>b<U0>@2c", 3, 2,
'\0',
"a<U0>b<U0>@3<U0>c", 0),
191 TEST (
"a<U0>b<U0>@2c", 2, 1,
'\0',
"a<U0>@2b<U0>@2c", 0),
192 TEST (
"<U0>ab<U0>@2c", 0, 3,
'\0',
"<U0>@3<U0>ab<U0>@2c", 0),
193 TEST (
"a<U0>bc<U0>@2", 6, 2,
'a',
"a<U0>bc<U0>@2aa", 0),
195 TEST (
"", 0, 4106,
'x',
"x@4106", 0),
196 TEST (
"x@4096", 0, 2,
'a',
"aax@4096", 0),
198 TEST (
"x@4096", 0, 2,
'a',
"aax@4096", 0),
199 TEST (
"x@4096", 1, 2,
'a',
"xaax@4095", 0),
200 TEST (
"x@4096", 1, 1,
'\0',
"x<U0>x@4095", 0),
202 TEST (
"x@127", 0, 1,
'x',
"x@128", 0),
203 TEST (
"x@200", 128, 7,
'x',
"x@207", 0),
204 TEST (
"x@331", 331, 3,
'x',
"x@334", 0),
205 TEST (
"x@539", 0, 1,
'x',
"x@540", 0),
206 TEST (
"x@539", 0, 873,
'x',
"x@1412", 0),
207 TEST (
"x@873", 873, 1411,
'x',
"x@2284", 0),
208 TEST (
"x@3694", 128, 1,
'x',
"x@3695", 0),
209 TEST (
"x@540", 0, 1,
'x',
"x@541", 0),
210 TEST (
"", 0, 3695,
'x',
"x@3695", 0),
212 TEST (
"a", 0, 4095,
'x',
"x@4095a", 0),
213 TEST (
"x@4096", 0, 2047,
'b',
"b@2047x@4096", 0),
214 TEST (
"x@4096", 2047, 2048,
'x',
"x@6144", 0),
216 TEST (
"last", 4, 4,
't',
"lasttttt", 0)
224iter_cref_test_cases [] = {
227#define TEST(lst, off, val, res, bthrow) \
228 { __LINE__, off, -1, -1, -1, val, lst, sizeof lst - 1, 0, \
229 0, res, sizeof res - 1, bthrow }
243 TEST (
"ab", 0,
'c',
"cab", 0),
245 TEST (
"", 0,
'b',
"b", 0),
246 TEST (
"", 0,
'\0',
"<U0>", 0),
248 TEST (
"<U0>", 0,
'a',
"a<U0>", 0),
249 TEST (
"<U0>", 1,
'a',
"<U0>a", 0),
250 TEST (
"<U0>", 0,
'\0',
"<U0>@2", 0),
251 TEST (
"<U0>", 1,
'\0',
"<U0>@2", 0),
253 TEST (
"cde", 0,
'a',
"acde", 0),
254 TEST (
"cde", 1,
'a',
"cade", 0),
255 TEST (
"cde", 2,
'a',
"cdae", 0),
256 TEST (
"cde", 3,
'a',
"cdea", 0),
258 TEST (
"a<U0>b<U0>@2c", 3,
'\0',
"a<U0>b<U0>@3c", 0),
259 TEST (
"<U0>ab<U0>@2c", 0,
'\0',
"<U0>@2ab<U0>@2c", 0),
260 TEST (
"a<U0>bc<U0>@2", 6,
'a',
"a<U0>bc<U0>@2a", 0),
262 TEST (
"x@4096", 0,
'a',
"ax@4096", 0),
263 TEST (
"x@4096", 1,
'a',
"xax@4095", 0),
264 TEST (
"x@4096", 1,
'\0',
"x<U0>x@4095", 0),
266 TEST (
"x@127", 0,
'x',
"x@128", 0),
267 TEST (
"x@206", 1,
'x',
"x@207", 0),
268 TEST (
"x@333", 333,
'x',
"x@334", 0),
269 TEST (
"x@539", 128,
'x',
"x@540", 0),
270 TEST (
"x@1411", 0,
'x',
"x@1412", 0),
271 TEST (
"x@2283", 10,
'x',
"x@2284", 0),
272 TEST (
"x@3694", 3694,
'x',
"x@3695", 0),
273 TEST (
"x@540", 538,
'x',
"x@541", 0),
275 TEST (
"last", 4,
't',
"lastt", 0)
283push_front_test_cases [] = {
286#define TEST(str, val, res) { \
287 __LINE__, -1, -1, -1, -1, val, str, sizeof str - 1, \
288 0, 0, res, sizeof res - 1, 0 }
299 TEST (
"",
'x',
"x" ),
300 TEST (
"<U0>",
'\0',
"<U0>@2" ),
301 TEST (
"",
'a',
"a" ),
302 TEST (
"bc",
'a',
"abc" ),
303 TEST (
"<U0> s",
't',
"t<U0> s" ),
304 TEST (
"<U0>@3b",
'a',
"a<U0>@3b" ),
305 TEST (
"<U0>b<U0>@2c",
'a',
"a<U0>b<U0>@2c" ),
306 TEST (
"ab<U0>@2c",
'\0',
"<U0>ab<U0>@2c" ),
307 TEST (
"b<U0>c<U0>@2",
'a',
"ab<U0>c<U0>@2" ),
308 TEST (
"x@4095",
'x',
"x@4096" ),
310 TEST (
"ast test",
'l',
"last test" )
318push_back_test_cases [] = {
321#define TEST(str, val, res) { \
322 __LINE__, -1, -1, -1, -1, val, str, sizeof str - 1, \
323 0, 0, res, sizeof res - 1, 0 }
334 TEST (
"",
'x',
"x" ),
335 TEST (
"<U0>",
'\0',
"<U0>@2" ),
336 TEST (
"",
'a',
"a" ),
337 TEST (
"ab",
'c',
"abc" ),
338 TEST (
"t<U0> ",
's',
"t<U0> s" ),
339 TEST (
"a<U0>@3",
'b',
"a<U0>@3b" ),
340 TEST (
"a<U0>b<U0>@2",
'c',
"a<U0>b<U0>@2c" ),
341 TEST (
"<U0>ab<U0>@2",
'c',
"<U0>ab<U0>@2c" ),
342 TEST (
"ab<U0>c<U0>",
'\0',
"ab<U0>c<U0>@2" ),
343 TEST (
"x@4095",
'x',
"x@4096" ),
345 TEST (
"last tes",
't',
"last test" )
350template <
class InputIterator,
class Distance>
360template<
class InputIterator>
364 std::size_t
dist = 0;
366 for (; first !=
last; ++first)
374template <
class List,
class Iterator>
396 lst.insert (first1, first2, last2);
404template <
class List,
class Iterator>
423 const std::size_t srclen_ = tdata.
arglen_;
425 const std::size_t
off =
427 const std::size_t ext = tdata.
ext2_;
440 lst.insert (first1, first2, last2);
447template <
class List,
class Iterator>
468 lst.insert (first1, first2, last2);
475template <
class T,
class Allocator>
480 typedef std::list <T, Allocator> List;
481 typedef typename List::iterator ListIter;
482 typedef typename List::const_iterator ListCIter;
496 std::ptrdiff_t exp_off =
Insert (iter_cref) ==
func.which_ ? tcase.
off : 0;
500 const std::size_t size1 = tdata.
strlen_;
501 const std::size_t off1 =
502 std::size_t (tcase.
off) < size1 ? std::size_t (tcase.
off) : size1;
504 const T arg_val = T::from_char (
char (tcase.
val));
512 std::size_t throw_count;
513 for (throw_count = 0; ; ++throw_count) {
516 const char* expected = 0;
519#ifndef _RWSTD_NO_EXCEPTIONS
525 expected = exceptions [1];
542 const List* ret_ptr = 0;
556 std::size_t newcnt = 0;
558 switch (
func.which_) {
560 case Insert (iter_size_cref): {
561 ListIter it (lst.begin ());
563 lst.insert (it, tcase.
size, arg_val);
569 case Insert (iter_cref): {
570 ListIter it (lst.begin ());
572 it = lst.insert (it, arg_val);
578 case Insert (iter_range): {
579 ret_ptr = &rng (lst, tdata);
580 newcnt = tcase.
size2;
584 case ListIds::push_front_cref:
585 lst.push_front (arg_val);
590 case ListIds::push_back_cref:
591 lst.push_back (arg_val);
597 RW_ASSERT (!
"logic error: unknown insert overload");
608 "line %d. %{$FUNCALL} called default/copy ctor "
609 "and operator=() %zu, %zu and %zu times, "
610 "respectively, 0, %zu, 0, expected",
621 const std::ptrdiff_t ret_off = ret_ptr - &lst;
625 "line %d. %{$FUNCALL} %{?}== begin() + %td, got %td%{;}"
626 "%{?}returned invalid reference, offset is %td%{;}",
632 static const int cwidth =
sizeof (
T);
634 const std::size_t got_size = lst.size ();
635 char*
const got =
new char [got_size + 1];
637 std::size_t
index = 0;
638 for (ListCIter it = lst.begin (),
639 end = lst.end (); it !=
end; ++it) {
640 got [
index++] = char (it->data_.val_);
643 got [got_size] =
'\0';
647 "line %d. %{$FUNCALL} expected \"%{X=*}\" with length "
648 "%zu, got %{/*.*Gs} with length %zu", __LINE__,
650 1, int (got_size), got, got_size);
652 if (tdata.
reslen_ == got_size) {
656 const T* pmatch = T::mismatch (tdata.
res_, got, got_size);
659 "line %d. %{$FUNCALL} expected \"%{X=*}\", "
660 "got %{/*.*Gs}, difference at offset %zu",
662 1, int (got_size), got, pmatch - tdata.
res_);
668#ifndef _RWSTD_NO_EXCEPTIONS
673 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
674 "unexpectedly%{;} caught std::%s(%#s)",
675 __LINE__, 0 != expected, expected,
caught, ex.what ());
680 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
681 "unexpectedly%{;} caught std::%s(%#s)",
682 __LINE__, 0 != expected, expected,
caught, ex.what ());
687 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
688 "unexpectedly%{;} caught %s",
689 __LINE__, 0 != expected, expected,
caught);
697 std::size_t (-1), std::size_t (-1));
712 else if (0 < tcase.
bthrow) {
714 "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
715 "%{:}unexpectedly caught %s%{;}",
729template <
class T,
class Allocator>
733 typedef std::list<T, Allocator> List;
742#define TEST(Iterator) do { \
743 typedef typename List::Iterator Iter; \
745 InsertRangePtrOverload<List, Iter> rng; \
746 test_insert ((T*)0, (Allocator*)0, rng, tdata); \
753#define TEST(Iterator) do { \
754 typedef typename List::Iterator Iter; \
756 InsertRangeOverload<List, Iter> rng; \
757 test_insert ((T*)0, (Allocator*)0, rng, tdata); \
770#define TEST(Iterator) do { \
771 typedef Iterator<T> Iter; \
773 InsertRange<List, Iter> rng; \
774 test_insert ((T*)0, (Allocator*)0, rng, tdata); \
783 rw_error (0, 0, __LINE__,
"bad iterator id");
797int main (
int argc,
char** argv)
804 Insert (sig), sig ## _test_cases, \
805 sizeof sig ## _test_cases / sizeof *sig ## _test_cases \
809 TEST (iter_size_cref),
814 ListIds::sig ## _cref, sig ## _test_cases, \
815 sizeof sig ## _test_cases / sizeof *sig ## _test_cases \
822 const std::size_t test_count =
sizeof tests /
sizeof *tests;
828 test_insert_func_array, tests, test_count);
void _rw_advance(InputIterator &it, Distance dist)
#define TEST(lst, off, arg, off2, size2, res, bthrow)
std::size_t _rw_distance(InputIterator first, InputIterator last)
void _rw_advance(InputIterator &it, Distance dist)
#define _RWSTD_CONST_CAST(T, x)
const ContainerFunc & func_
const ContainerTestCase & tcase_
_TEST_EXPORT void rw_check_leaks(const SharedAlloc *=0, int=0, _RWSTD_SIZE_T=0, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX)
_TEST_EXPORT int rw_run_cont_test(int, char **, const char *, const char *, ContainerIds::ContainerId, ContainerTestFunc *, const ContainerTest *, _RWSTD_SIZE_T)
#define DEFINE_CONTAINER_TEST_FUNCTIONS(fname)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_error(int, const char *, int, const char *,...)
_TEST_EXPORT rwt_free_store * rwt_get_free_store(rwt_free_store *)
static ContIter begin(List &cont, ContIter *)
ContainerIds::ElemId elem_id_
ContainerIds::IteratorId iter_id_
virtual List & operator()(List &lst, const ContainerTestCaseData< ListVal > &tdata) const
virtual List & operator()(List &lst, const ContainerTestCaseData< ListVal > &tdata) const
virtual List & operator()(List &lst, const ContainerTestCaseData< ListVal > &tdata) const
void assert_equal(const ListState &state, int line, int case_line, const char *when) const
static SharedAlloc * instance(SharedAlloc *=0)
_RWSTD_SIZE_T throw_at_calls_[n_funs]
static _RWSTD_SIZE_T n_total_op_assign_
static bool is_total(_RWSTD_SIZE_T count, _RWSTD_SIZE_T n_def_ctor, _RWSTD_SIZE_T n_copy_ctor, _RWSTD_SIZE_T n_op_assign, _RWSTD_SIZE_T n_op_eq, _RWSTD_SIZE_T n_op_lt)
static _RWSTD_SIZE_T count_
static void reset_totals()
static _RWSTD_SIZE_T n_total_def_ctor_
static _RWSTD_SIZE_T n_total_copy_ctor_
_RWSTD_SIZE_T * throw_at_calls_[2]
_RWSTD_SIZE_T new_calls_[2]