39#define Assign(sig) ListIds::assign_ ## sig
41static const char*
const exceptions[] = {
42 "unknown exception",
"bad_alloc",
"exception"
53#define TEST(lst, arg, off, size, res, bthrow) { \
54 __LINE__, -1, -1, off, size, -1, \
55 lst, sizeof lst - 1, \
56 arg, sizeof arg - 1, res, sizeof res - 1, bthrow \
77 TEST (
"ab",
"c", 0, 1,
"c", 0),
79 TEST (
"",
"", 0, 0,
"", 0),
80 TEST (
"",
"abc", 1, 1,
"b", 0),
81 TEST (
"",
"<U0>", 0, 1,
"<U0>", 0),
83 TEST (
"<U0>",
"", 0, 0,
"", 0),
85 TEST (
"abc",
"", 0, 0,
"", 0),
87 TEST (
"<U0>",
"a", 0, 1,
"a", 0),
88 TEST (
"<U0>",
"<U0>@2", 1, 1,
"<U0>", 0),
89 TEST (
"<U0>",
"<U0>@2", 0, 2,
"<U0>@2", 0),
90 TEST (
"<U0>",
"<U0>@2", 1, 5,
"<U0>", 0),
92 TEST (
"cde",
"ab", 0, 2,
"ab", 0),
93 TEST (
"cde",
"ab", 0, 1,
"a", 0),
94 TEST (
"cde",
"ab", 1, 5,
"b", 0),
96 TEST (
"ab",
"c<U0>e", 0, 3,
"c<U0>e", 0),
97 TEST (
"ab",
"c<U0>e", 1, 2,
"<U0>e", 0),
98 TEST (
"ab",
"c<U0>e", 0, 2,
"c<U0>", 0),
100 TEST (
"<U0>e<U0>",
"<U0>ab<U0>@2c", 0, 9,
"<U0>ab<U0>@2c", 0),
101 TEST (
"<U0>e<U0>",
"<U0>ab<U0>@2c", 0, 3,
"<U0>ab", 0),
102 TEST (
"a<U0>b<U0>@2c",
"<U0>e<U0>", 0, 3,
"<U0>e<U0>", 0),
103 TEST (
"a<U0>b<U0>@2c",
"<U0>@2e<U0>", 0, 2,
"<U0>@2", 0),
104 TEST (
"<U0>ab<U0>@2c",
"<U0>e<U0>", 2, 1,
"<U0>", 0),
105 TEST (
"<U0>ab<U0>@2c",
"<U0>e<U0>", 2, 9,
"<U0>", 0),
106 TEST (
"a<U0>bc<U0>@2",
"<U0>e", 0, 2,
"<U0>e", 0),
108 TEST (
"x@4096",
"", 0, 0,
"", 0),
109 TEST (
"",
"x@4096", 9, 2,
"xx", 0),
110 TEST (
"",
"x@4096", 9, 0,
"", 0),
111 TEST (
"abc",
"x@4096", 2, 1,
"x", 0),
112 TEST (
"x@4096",
"x@4096", 2, 3,
"xxx", 0),
113 TEST (
"",
"x@4096", 0, 4096,
"x@4096", 0),
114 TEST (
"",
"x@4096", 100, 2000,
"x@2000", 0),
116 TEST (
"",
"x@207", 0, 207,
"x@207", 0),
117 TEST (
"x@128",
"x@334", 10, 207,
"x@207", 0),
118 TEST (
"x@540",
"x@207", 50, 128,
"x@128", 0),
119 TEST (
"",
"x@1412", 128, 873,
"x@873", 0),
120 TEST (
"x@128",
"x@1412", 0, 1412,
"x@1412", 0),
121 TEST (
"x@3695",
"x@1412", 207, 540,
"x@540", 0),
122 TEST (
"x@872",
"x@874", 1, 873,
"x@873", 0),
123 TEST (
"x@873",
"x@3695", 10, 2284,
"x@2284", 0),
125 TEST (
"",
"<U0>", 2, 0,
"", 1),
126 TEST (
"",
"a", 2, 0,
"", 1),
127 TEST (
"",
"x@4096", 4106, 0,
"", 1),
129 TEST (
"last",
"test", 0, 4,
"test", 0)
137size_cref_test_cases [] = {
140#define TEST(lst, size, val, res, bthrow) { \
141 __LINE__, -1, size, -1, -1, val, \
142 lst, sizeof lst - 1, \
143 0, 0, res, sizeof res - 1, bthrow \
158 TEST (
"ab", 1,
'c',
"c", 0),
160 TEST (
"", 0,
' ',
"", 0),
161 TEST (
"", 1,
'b',
"b", 0),
162 TEST (
"", 3,
'b',
"bbb", 0),
164 TEST (
"<U0>", 0,
' ',
"", 0),
165 TEST (
"", 2,
'\0',
"<U0>@2", 0),
167 TEST (
"<U0>", 1,
'a',
"a", 0),
168 TEST (
"<U0>", 1,
'\0',
"<U0>", 0),
169 TEST (
"<U0>", 2,
'\0',
"<U0>@2", 0),
170 TEST (
"<U0>", 0,
'\0',
"", 0),
172 TEST (
"cde", 3,
'a',
"aaa", 0),
173 TEST (
"ab", 2,
'\0',
"<U0>@2", 0),
174 TEST (
"ab", 1,
'\0',
"<U0>", 0),
176 TEST (
"a<U0>b<U0>@2c", 2,
'\0',
"<U0>@2", 0),
177 TEST (
"a<U0>b<U0>@2c", 1,
'\0',
"<U0>", 0),
178 TEST (
"<U0>ab<U0>@2c", 3,
'\0',
"<U0>@3", 0),
179 TEST (
"a<U0>bc<U0>@2", 2,
'a',
"aa", 0),
181 TEST (
"", 4096,
'x',
"x@4096", 0),
182 TEST (
"x@4096", 0,
'x',
"", 0),
184 TEST (
"x@127", 128,
'x',
"x@128", 0),
185 TEST (
"x@200", 207,
'x',
"x@207", 0),
186 TEST (
"x@334", 128,
'x',
"x@128", 0),
187 TEST (
"", 540,
'x',
"x@540", 0),
188 TEST (
"xx", 873,
'x',
"x@873", 0),
189 TEST (
"x@873", 1412,
'x',
"x@1412", 0),
190 TEST (
"x@3695", 207,
'x',
"x@207", 0),
191 TEST (
"x@540", 3695,
'x',
"x@3695", 0),
193 TEST (
"last", 4,
't',
"tttt", 0)
198template <
class InputIterator,
class Distance>
210template <
class List,
class Iterator>
228 lst.assign (first,
last);
237template <
class List,
class Iterator>
249 const bool reverse_iter =
263 lst.assign (first,
last);
272template <
class List,
class Iterator>
289 lst.assign (first,
last);
296template <
class T,
class Allocator>
301 typedef std::list <T, Allocator> List;
302 typedef typename List::iterator ListIter;
303 typedef typename List::const_iterator ListCIter;
320 std::size_t throw_count;
321 for (throw_count = 0; ; ++throw_count) {
324 const char* expected = 0;
327#ifndef _RWSTD_NO_EXCEPTIONS
333 expected = exceptions [1];
353 switch (
func.which_) {
355 case Assign (size_cref): {
356 const T val = T::from_char (
char (tcase.
val));
366 RW_ASSERT (!
"test logic error: unknown assign overload");
370 static const int cwidth =
sizeof (
T);
372 const std::size_t got_size = lst.size ();
373 char*
const got =
new char [got_size + 1];
375 std::size_t
index = 0;
376 for (ListCIter it = lst.begin (),
377 end = lst.end (); it !=
end; ++it) {
378 got [
index++] = char (it->data_.val_);
381 got [got_size] =
'\0';
385 "line %d. %{$FUNCALL}: expected \"%{X=*}\" with length "
386 "%zu, got %{/*.*Gs} with length %zu", __LINE__,
388 1, int (got_size), got, got_size);
390 if (tdata.
reslen_ == got_size) {
394 const std::size_t match =
398 "line %d. %{$FUNCALL}: expected \"%{X=*}\", "
399 "got %{/*.*Gs}, difference at off %zu",
401 1, int (got_size), got, match);
407#ifndef _RWSTD_NO_EXCEPTIONS
412 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
413 "unexpectedly%{;} caught std::%s(%#s)",
414 __LINE__, 0 != expected, expected,
caught, ex.what ());
419 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
420 "unexpectedly%{;} caught std::%s(%#s)",
421 __LINE__, 0 != expected, expected,
caught, ex.what ());
426 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
427 "unexpectedly%{;} caught %s",
428 __LINE__, 0 != expected, expected,
caught);
436 std::size_t (-1), std::size_t (-1));
446 else if (0 < tcase.
bthrow) {
448 "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
449 "%{:}unexpectedly caught %s%{;}",
463template <
class T,
class Allocator>
467 typedef std::list<T, Allocator> List;
476#define TEST(Iterator) do { \
477 typedef typename List::Iterator Iter; \
479 AssignRangePtrOverload<List, Iter> rng; \
480 test_assign ((T*)0, (Allocator*)0, rng, tdata); \
487#define TEST(Iterator) do { \
488 typedef typename List::Iterator Iter; \
490 AssignRangeOverload<List, Iter> rng; \
491 test_assign ((T*)0, (Allocator*)0, rng, tdata); \
505#define TEST(Iterator) do { \
506 typedef Iterator<T> Iter; \
508 AssignRange<List, Iter> rng; \
509 test_assign ((T*)0, (Allocator*)0, rng, tdata); \
518 rw_error (0, 0, __LINE__,
"bad iterator id");
532int main (
int argc,
char** argv)
539 Assign (sig), sig ## _test_cases, \
540 sizeof sig ## _test_cases / sizeof *sig ## _test_cases \
547 const std::size_t test_count =
sizeof tests /
sizeof *tests;
553 test_assign_func_array, tests, test_count);
#define TEST(lst, arg, off, size, res, bthrow)
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 _RWSTD_SIZE_T rw_match(const char *, const char *, _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 *)
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
static ContIter begin(List &cont, ContIter *)
ContainerIds::IteratorId iter_id_
static SharedAlloc * instance(SharedAlloc *=0)
_RWSTD_SIZE_T throw_at_calls_[n_funs]
_RWSTD_SIZE_T * throw_at_calls_[2]
_RWSTD_SIZE_T new_calls_[2]