39#define Cons(sig) ListIds::ctor_ ## sig
40#define OpSet(sig) ListIds::op_set_ ## sig
42static const char*
const exceptions[] = {
43 "unknown exception",
"bad_alloc",
"exception",
"UserClass::CopyCtor"
51#define alloc_test_cases void_test_cases
56#define TEST(dummy) { \
57 __LINE__, -1, -1, -1, -1, -1, \
58 0, 0, dummy, sizeof dummy - 1, \
75ccont_test_cases [] = {
78#define TEST(arg, res) { \
79 __LINE__, -1, -1, -1, -1, -1, \
80 0, 0, arg, sizeof arg - 1, \
81 res, sizeof res - 1, 0 \
92 TEST (
"<U0>",
"<U0>"),
93 TEST (
"<U0>@2",
"<U0>@2"),
97 TEST (
"cdefaihjb",
"cdefaihjb"),
99 TEST (
"<U0>@2ab",
"<U0>@2ab"),
100 TEST (
"a<U0>@2b",
"a<U0>@2b"),
101 TEST (
"ab<U0>@2",
"ab<U0>@2"),
102 TEST (
"abefdcc<U0>a",
"abefdcc<U0>a"),
104 TEST (
"x@128",
"x@128"),
105 TEST (
"x@207",
"x@207"),
106 TEST (
"x@334",
"x@334"),
107 TEST (
"x@540",
"x@540"),
108 TEST (
"x@873",
"x@873"),
109 TEST (
"x@1412",
"x@1412"),
110 TEST (
"x@3695",
"x@3695"),
111 TEST (
"x@4096",
"x@4096"),
113 TEST (
"last test",
"last test")
121#define range_alloc_test_cases range_test_cases
126#define TEST(arg, off, size, res, bthrow) { \
127 __LINE__, -1, -1, off, size, -1, \
128 0, 0, arg, sizeof arg - 1, \
129 res, sizeof res - 1, bthrow \
142 TEST (
"ab", 0, 2,
"ab", 0),
144 TEST (
"", 0, 0,
"", 0),
145 TEST (
"<U0>", 0, 1,
"<U0>", 0),
146 TEST (
"<U0>@2", 0, 2,
"<U0>@2", 0),
148 TEST (
"a", 0, 1,
"a", 0),
149 TEST (
"bcd", 0, 3,
"bcd", 0),
150 TEST (
"cdefaihjb", 0, 9,
"cdefaihjb", 0),
152 TEST (
"<U0>@2ab", 0, 4,
"<U0>@2ab", 0),
153 TEST (
"a<U0>@2b", 0, 4,
"a<U0>@2b", 0),
154 TEST (
"ab<U0>@2", 0, 4,
"ab<U0>@2", 0),
155 TEST (
"abefdcc<U0>a", 0, 9,
"abefdcc<U0>a", 0),
157 TEST (
"x@207", 0, 207,
"x@207", 0),
158 TEST (
"x@334", 10, 207,
"x@207", 0),
159 TEST (
"x@207", 50, 128,
"x@128", 0),
160 TEST (
"x@1412", 128, 873,
"x@873", 0),
161 TEST (
"x@1412", 0, 1412,
"x@1412", 0),
162 TEST (
"x@1412", 207, 540,
"x@540", 0),
163 TEST (
"x@874", 1, 873,
"x@873", 0),
164 TEST (
"x@3695", 10, 2284,
"x@2284", 0),
165 TEST (
"x@4096", 0, 4096,
"x@4096", 0),
167 TEST (
"last test", 0, 9,
"last test", 0)
175size_test_cases [] = {
178#define TEST(size, res) { \
179 __LINE__, -1, size, -1, -1, 0, \
181 res, sizeof res - 1, 0 \
192 TEST (10,
"<U0>@10"),
193 TEST (128,
"<U0>@128"),
194 TEST (207,
"<U0>@207"),
195 TEST (540,
"<U0>@540"),
196 TEST (873,
"<U0>@873"),
197 TEST (1412,
"<U0>@1412"),
198 TEST (3695,
"<U0>@3695"),
199 TEST (4096,
"<U0>@4096")
207#define size_cref_alloc_test_cases size_cref_test_cases
209size_cref_test_cases [] = {
212#define TEST(size, val, res) { \
213 __LINE__, -1, size, -1, -1, val, \
215 res, sizeof res - 1, 0 \
225 TEST (1,
'\0',
"<U0>"),
228 TEST (2,
'\0',
"<U0>@2"),
230 TEST (5,
'\0',
"<U0>@5"),
231 TEST (10,
'a',
"aaaaaaaaaa"),
233 TEST (128,
'x',
"x@128"),
234 TEST (207,
'x',
"x@207"),
235 TEST (540,
'x',
"x@540"),
236 TEST (873,
'x',
"x@873"),
237 TEST (1412,
'x',
"x@1412"),
238 TEST (3695,
'x',
"x@3695"),
240 TEST (4096,
'x',
"x@4096"),
242 TEST (4,
't',
"tttt")
249ccont_op_set_test_cases [] = {
252#define TEST(str, arg, res, bthrow) { \
253 __LINE__, -1, -1, -1, -1, -1, \
254 str, sizeof str - 1, arg, sizeof arg - 1, \
255 res, sizeof res - 1, bthrow \
267 TEST (
"",
"ab",
"ab", 0),
269 TEST (
"",
"",
"", 0),
270 TEST (
"abc",
"",
"", 0),
271 TEST (
"",
"<U0>",
"<U0>", 0),
272 TEST (
"abc",
"<U0>",
"<U0>", 0),
274 TEST (
"",
"a",
"a", 0),
275 TEST (
"<U0>@2",
"a",
"a", 0),
276 TEST (
"a",
"bcd",
"bcd", 0),
277 TEST (
"x@4096",
"bcd",
"bcd", 0),
278 TEST (
"",
"cdefaihjb",
"cdefaihjb", 0),
279 TEST (
"a<U0>b",
"cdefaihjb",
"cdefaihjb", 0),
281 TEST (
"",
"<U0>@2ab",
"<U0>@2ab", 0),
282 TEST (
"c<U0>d",
"<U0>@2ab",
"<U0>@2ab", 0),
283 TEST (
"",
"a<U0>@2b",
"a<U0>@2b", 0),
284 TEST (
"bcd",
"a<U0>@2b",
"a<U0>@2b", 0),
285 TEST (
"<U0>",
"ab<U0>@2",
"ab<U0>@2", 0),
286 TEST (
"x@4096",
"ab<U0>@2",
"ab<U0>@2", 0),
287 TEST (
"<U0>a",
"abefdcc<U0>a",
"abefdcc<U0>a", 0),
288 TEST (
"x@4096",
"abefdcc<U0>a",
"abefdcc<U0>a", 0),
290 TEST (
"",
"x@207",
"x@207", 0),
291 TEST (
"x@128",
"x@207",
"x@207", 0),
292 TEST (
"x@540",
"x@207",
"x@207", 0),
293 TEST (
"",
"x@1412",
"x@1412", 0),
294 TEST (
"x@128",
"x@1412",
"x@1412", 0),
295 TEST (
"x@3695",
"x@1412",
"x@1412", 0),
296 TEST (
"x@872",
"x@873",
"x@873", 0),
297 TEST (
"x@873",
"x@3695",
"x@3695", 0),
299 TEST (
"abc",
"x@4096",
"x@4096", 0),
302 TEST (
"a<U0>b<U0>", 0,
"a<U0>b<U0>", 0),
303 TEST (
"x@4096", 0,
"x@4096", 0),
305 TEST (
"",
"last test",
"last test", 0)
312template <
class List,
class Iterator>
335 List*
tmp =
new List (first,
last);
344template <
class List,
class Iterator>
367 List*
tmp =
new List (first,
last);
374template <
class InputIterator,
class Distance>
386template <
class List,
class Iterator>
403 const std::size_t
off = reverse_iter ?
405 const std::size_t ext = tdata.
ext2_;
419 List*
tmp =
new List (first,
last);
426template <
class T,
class Allocator>
428 std::list <T, Allocator> > &rng,
431 typedef std::list <T, Allocator> List;
432 typedef typename List::iterator ListIter;
433 typedef typename List::const_iterator ListCIter;
442 const List& arg_list =
arg;
443 const T arg_val = T::from_char (
char (tcase.
val));
452 const char* expected = 0;
455#ifndef _RWSTD_NO_EXCEPTIONS
462 expected = exceptions [3];
486 const std::size_t arg_count = std::size_t (tcase.
size);
499 ret_ptr =
new List ();
503 ret_ptr =
new List (arg_alc);
507 ret_ptr =
new List (arg_list);
511 ret_ptr =
new List (arg_count);
514 case Cons (size_cref):
515 ret_ptr =
new List (arg_count, arg_val);
518 case Cons (size_cref_alloc):
519 ret_ptr =
new List (arg_count, arg_val, arg_alc);
523 ret_ptr = &rng (
arg, tdata);
526 case Cons (range_alloc):
527 ret_ptr = &rng (
arg, tdata);
531 RW_ASSERT (!
"logic error: unknown constructor overload");
535 static const int cwidth =
sizeof (
T);
539 "line %d. %{$FUNCALL} expected \"%{X=*}\", got null",
540 __LINE__, cwidth, int (tdata.
reslen_), tdata.
res_);
555 "line %d. %{$FUNCALL} called default/copy ctor "
556 "and operator=() %zu, %zu, and %zu times, "
557 "respectively, %zu, %zu, 0 expected",
565 const std::size_t got_size = ret_ptr->size ();
566 char*
const got =
new char [got_size + 1];
568 std::size_t
index = 0;
569 for (ListCIter it = ret_ptr->begin (),
570 end = ret_ptr->end (); it !=
end; ++it) {
571 got [
index++] = char (it->data_.val_);
574 got [got_size] =
'\0';
578 "line %d. %{$FUNCALL} expected \"%{X=*}\" with "
579 "length %zu, got %{/*.*Gs} with length %zu",
583 1, int (got_size), got, got_size);
585 if (tdata.
reslen_ == got_size) {
589 const std::size_t match =
593 "line %d. %{$FUNCALL} expected \"%{X=*}\", got "
594 "%{/*.*Gs}, difference at offset %zu",
597 1, int (got_size), got, match);
606#ifndef _RWSTD_NO_EXCEPTIONS
611 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
612 "unexpectedly%{;} caught %s (id_ = %d)",
613 __LINE__, 0 != expected, expected,
caught,
619 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
620 "unexpectedly%{;} caught std::%s(%#s)",
621 __LINE__, 0 != expected, expected,
caught,
627 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
628 "unexpectedly%{;} caught std::%s(%#s)",
629 __LINE__, 0 != expected, expected,
caught,
635 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
636 "unexpectedly%{;} caught %s",
637 __LINE__, 0 != expected, expected,
caught);
651 const std::size_t expect_blocks = nblocks;
654 "line %d. %{$FUNCALL} allocated %td bytes in %td blocks",
655 __LINE__, nbytes, expect_blocks);
659 "line %d. %{$FUNCALL} leaked %zu value(s) "
660 "of %zu after %{?}an exception %s%{:}call%{;}",
672 else if (0 < tcase.
bthrow) {
674 "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
675 "%{:}unexpectedly caught %s%{;}",
685template <
class T,
class Allocator>
689 typedef std::list <T, Allocator> List;
690 typedef typename List::iterator ListIter;
691 typedef typename List::const_iterator ListCIter;
702 const List& arg_list = tcase.
arg ?
arg : lst;
710 std::size_t throw_count;
711 for (throw_count = 0; ; ++throw_count) {
714 const char* expected = 0;
717#ifndef _RWSTD_NO_EXCEPTIONS
724 expected = exceptions [1];
762 RW_ASSERT (!
"logic error: unknown operator= overload");
765 if (is_class && &lst != &arg_list) {
771 && total_copy == tdata.
reslen_;
774 "line %d. %{$FUNCALL} called default ctor and "
775 "copy ctor + operator=() %zu, and %zu times, "
776 "respectively, 0, and %zu expected",
783 static const int cwidth =
sizeof (
T);
785 const std::size_t got_size = lst.size ();
786 char*
const got =
new char [got_size + 1];
788 std::size_t
index = 0;
789 for (ListCIter it = lst.begin (),
790 end = lst.end (); it !=
end; ++it) {
791 got [
index++] = char (it->data_.val_);
794 got [got_size] =
'\0';
798 "line %d. %{$FUNCALL} expected \"%{X=*}\" with "
799 "length %zu, got %{/*.*Gs} with length %zu",
802 tdata.
reslen_, 1, int (got_size), got, got_size);
804 if (tdata.
reslen_ == got_size) {
808 const std::size_t match =
812 "line %d. %{$FUNCALL} expected \"%{X=*}\", "
813 "got %{/*.*Gs}, difference at offset %zu",
814 __LINE__, cwidth, int (tdata.
reslen_),
815 tdata.
res_, 1, int (got_size), got, match);
821#ifndef _RWSTD_NO_EXCEPTIONS
826 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
827 "unexpectedly%{;} caught std::%s(%#s)",
828 __LINE__, 0 != expected, expected,
caught,
834 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
835 "unexpectedly%{;} caught std::%s(%#s)",
836 __LINE__, 0 != expected, expected,
caught,
842 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
843 "unexpectedly%{;} caught %s",
844 __LINE__, 0 != expected, expected,
caught);
852 std::size_t (-1), std::size_t (-1));
862 else if (0 < tcase.
bthrow) {
864 "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
865 "%{:}unexpectedly caught %s%{;}",
879template <
class T,
class Allocator>
883 typedef std::list<T, Allocator> List;
899#define TEST(Iterator) do { \
900 typedef Iterator<T> Iter; \
902 ConsRange<List, Iter> rng; \
903 test_cons ((T*)0, (Allocator*)0, rng, tdata); \
914#define TEST(Iterator) do { \
915 typedef typename List::Iterator Iter; \
917 ConsRangePtrOverload<List, Iter> rng; \
918 test_cons ((T*)0, (Allocator*)0, rng, tdata); \
928#define TEST(Iterator) do { \
929 typedef typename List::Iterator Iter; \
931 ConsRangeOverload<List, Iter> rng; \
932 test_cons ((T*)0, (Allocator*)0, rng, tdata); \
939 TEST (reverse_iterator);
942 TEST (const_reverse_iterator);
946 rw_error (0, 0, __LINE__,
"bad iterator id");
960int main (
int argc,
char** argv)
969 Cons (sig), sig ## _test_cases, \
970 sizeof sig ## _test_cases / sizeof *sig ## _test_cases \
978 TEST (size_cref_alloc),
984 OpSet (sig), sig ## _op_set_test_cases, \
985 sizeof sig ## _op_set_test_cases \
986 / sizeof *sig ## _op_set_test_cases \
992 const std::size_t test_count =
sizeof tests /
sizeof *tests;
998 test_cons_func_array, tests, test_count);
void _rw_advance(InputIterator &it, Distance dist)
void test_cons(T *, Allocator *, const ContRangeBase< std::list< T, Allocator > > &rng, const ContainerTestCaseData< T > &tdata)
void _rw_advance(InputIterator &it, Distance dist)
void test_op_set(T *, Allocator *, const ContainerTestCaseData< T > &tdata)
#define _RWSTD_STATIC_CAST(T, x)
#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 _RWSTD_SIZE_T rwt_check_leaks(_RWSTD_SIZE_T *, const rwt_free_store *)
_TEST_EXPORT rwt_free_store * rwt_get_free_store(rwt_free_store *)
List::allocator_type ListAlloc
virtual List & operator()(List &list_arg, const ContainerTestCaseData< ListVal > &tdata) const
virtual List & operator()(List &, const ContainerTestCaseData< ListVal > &tdata) const
List::allocator_type ListAlloc
List::allocator_type ListAlloc
virtual List & operator()(List &, 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]
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 copy_ctor_throw_count_
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]