40#define Size(sig) ListIds::size_ ## sig
41#define MaxSize(sig) ListIds::max_size_ ## sig
42#define Resize(sig) ListIds::resize_ ## sig
43#define Clear(sig) ListIds::clear_ ## sig
44#define Empty(sig) ListIds::empty_ ## sig
46static const char*
const exceptions[] = {
47 "unknown exception",
"bad_alloc",
"exception"
55size_void_test_cases [] = {
58#define TEST(str, res) { \
59 __LINE__, -1, -1, -1, -1, -1, \
60 str, sizeof str - 1, 0, 0, \
78 TEST (
"test string", 11),
79 TEST (
"Test String", 11),
82 TEST (
"Test<U0>string", 11),
84 TEST (
"<U0>a<U0>b", 4),
87 TEST (
"a<U0>@2b<U0>", 5),
88 TEST (
"a<U0>b<U0>@2c", 6),
89 TEST (
"a<U0>b<U0>c<U0>@2", 7),
96 TEST (
"x@1412", 1412),
97 TEST (
"x@2284", 2284),
98 TEST (
"x@3695", 3695),
99 TEST (
"x@4096", 4096),
109max_size_void_test_cases [] = {
113 __LINE__, -1, -1, -1, -1, -1, \
114 str, sizeof str - 1, 0, 0, \
129 TEST (
"test string"),
130 TEST (
"a<U0>b<U0>c<U0>@2"),
145resize_size_val_test_cases [] = {
148#define TEST(str, size, val, res, bthrow) { \
149 __LINE__, -1, size, -1, -1, val, \
150 str, sizeof str - 1, 0, 0, \
151 res, sizeof res - 1, bthrow \
164 TEST (
"", 0,
'a',
"", 0),
165 TEST (
"", 5,
'\0',
"<U0>@3<U0>@2", 0),
166 TEST (
"", 334,
'x',
"x@334", 0),
168 TEST (
"<U0>", 0,
'a',
"", 0),
169 TEST (
"<U0>", 2,
'a',
"<U0>a", 0),
170 TEST (
"<U0>", 1,
'a',
"<U0>", 0),
171 TEST (
"<U0>", 128,
'a',
"<U0>a@127", 0),
173 TEST (
"a", 0,
'a',
"", 0),
174 TEST (
"a", 2,
'\0',
"a<U0>", 0),
175 TEST (
"a", 540,
'a',
"a@540", 0),
177 TEST (
"a<U0>@3b", 10,
'a',
"a<U0>@3baaaaa", 0),
178 TEST (
"ab<U0>@3", 10,
'a',
"ab<U0>@3aaaaa", 0),
179 TEST (
"<U0>@3ab", 10,
'a',
"<U0>@3abaaaaa", 0),
180 TEST (
"a<U0>@3b", 7,
'\0',
"a<U0>@3b<U0>@2", 0),
181 TEST (
"ab<U0>@3", 7,
'\0',
"ab<U0>@3<U0>@2", 0),
182 TEST (
"<U0>@3ba", 7,
'\0',
"<U0>@3ba<U0>@2", 0),
184 TEST (
"a<U0>b<U0>c<U0>@2", 6,
'a',
"a<U0>b<U0>c<U0>", 0),
185 TEST (
"a<U0>b<U0>c<U0>@2", 5,
'\0',
"a<U0>b<U0>c", 0),
186 TEST (
"<U0>ba<U0>c<U0>@2", 1,
'\0',
"<U0>", 0),
187 TEST (
"<U0>ba<U0>c<U0>@2", 0,
'\0',
"", 0),
189 TEST (
"x@540", 127,
'a',
"x@127", 0),
190 TEST (
"x@873", 127,
'a',
"x@127", 0),
191 TEST (
"x@1412", 127,
'a',
"x@127", 0),
192 TEST (
"x@2284", 127,
'a',
"x@127", 0),
194 TEST (
"x@127", 128,
'a',
"x@127a", 0),
195 TEST (
"x@128", 207,
'a',
"x@128a@79", 0),
196 TEST (
"x@207", 334,
'a',
"x@207a@127", 0),
197 TEST (
"x@334", 540,
'a',
"x@334a@206", 0),
198 TEST (
"x@540", 873,
'a',
"x@540a@333", 0),
199 TEST (
"x@873", 1412,
'a',
"x@873a@539", 0),
200 TEST (
"x@1412", 2284,
'a',
"x@1412a@872", 0),
201 TEST (
"x@2284", 3695,
'a',
"x@2284a@1411", 0),
203 TEST (
"last", 4,
't',
"last", 0)
211resize_size_test_cases [] = {
214#define TEST(str, size, res, bthrow) { \
215 __LINE__, -1, size, -1, -1, -1, \
216 str, sizeof str - 1, 0, 0, \
217 res, sizeof res - 1, bthrow \
229 TEST (
"", 5,
"\0@5", 0),
230 TEST (
"", 334,
"\0@334", 0),
232 TEST (
"<U0>", 0,
"", 0),
233 TEST (
"<U0>", 2,
"\0@2", 0),
234 TEST (
"<U0>", 1,
"\0", 0),
235 TEST (
"<U0>", 127,
"\0@127", 0),
237 TEST (
"a", 0,
"", 0),
238 TEST (
"a", 2,
"a\0", 0),
239 TEST (
"a", 539,
"a\0@538", 0),
241 TEST (
"a<U0>@3b", 10,
"a<U0>@3b\0@5", 0),
242 TEST (
"ab<U0>@3", 10,
"ab<U0>@3\0@5", 0),
243 TEST (
"<U0>@3ab", 10,
"<U0>@3ab\0@5", 0),
244 TEST (
"a<U0>@3b", 7,
"a<U0>@3b\0@2", 0),
245 TEST (
"ab<U0>@3", 7,
"ab<U0>@3\0@2", 0),
246 TEST (
"<U0>@3ba", 7,
"<U0>@3ba\0@2", 0),
248 TEST (
"a<U0>b<U0>c<U0>@2", 5,
"a<U0>b<U0>c", 0),
249 TEST (
"a<U0>b<U0>c<U0>@2", 4,
"a<U0>b<U0>", 0),
250 TEST (
"<U0>ba<U0>c<U0>@2", 1,
"<U0>", 0),
251 TEST (
"<U0>ba<U0>c<U0>@2", 0,
"", 0),
253 TEST (
"x@540", 127,
"x@127", 0),
254 TEST (
"x@873", 127,
"x@127", 0),
255 TEST (
"x@1412", 127,
"x@127", 0),
256 TEST (
"x@2284", 127,
"x@127", 0),
258 TEST (
"x@127", 128,
"x@127\0", 0),
259 TEST (
"x@128", 207,
"x@128\0@79", 0),
260 TEST (
"x@207", 334,
"x@207\0@127", 0),
261 TEST (
"x@334", 540,
"x@334\0@206", 0),
262 TEST (
"x@540", 873,
"x@540\0@333", 0),
263 TEST (
"x@873", 1412,
"x@873\0@539", 0),
264 TEST (
"x@1412", 2284,
"x@1412\0@872", 0),
265 TEST (
"x@2284", 3695,
"x@2284\0@1411", 0),
267 TEST (
"last", 4,
"last", 0)
275clear_void_test_cases [] = {
279 __LINE__, -1, -1, -1, -1, -1, \
280 str, sizeof str - 1, 0, 0, \
295 TEST (
"test string"),
296 TEST (
"a<U0>b<U0>c<U0>@2"),
316empty_void_test_cases [] = {
319#define TEST(str, res) { \
320 __LINE__, -1, -1, -1, -1, -1, \
321 str, sizeof str - 1, 0, 0, \
335 TEST (
"<U0>ab<U0>c", 0),
345template <
class T,
class Allocator>
349 typedef std::list<T, Allocator> List;
350 typedef typename List::iterator ListIter;
351 typedef typename List::const_iterator ListCIter;
366 const T arg_val = T::from_char (-1 != tcase.
val ? char (tcase.
val) : char ());
374 std::size_t throw_count;
375 for (throw_count = 0; ; ++throw_count) {
378 const char* expected = 0;
381#ifndef _RWSTD_NO_EXCEPTIONS
387 expected = exceptions [1];
388 *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_count + 1;
419 switch (
func.which_) {
426 res = clst.max_size ();
430 lst.resize (tcase.
size, arg_val);
434 lst.resize (tcase.
size);
442 res = clst.empty () ? 1 : 0;
446 RW_ASSERT (!
"test logic error: unknown capacity overload");
451 (
func.which_ == ListIds::clear_void
452 ||
func.which_ == ListIds::resize_size
453 ||
func.which_ == ListIds::resize_size_val)) {
461 std::size_t new_count = x_count_save + nctors -
ndtors;
463 std::size_t ndefctors = 0;
465 if (
func.which_ == ListIds::resize_size_val)
467 else if (
func.which_ == ListIds::resize_size)
473 "line %d. %{$FUNCALL} called default/copy ctor "
474 "and operator=() %zu, %zu, and %zu times, "
475 "respectively, %zu, %zu, 0 expected",
484 if (
func.which_ == ListIds::size_void
485 ||
func.which_ == ListIds::empty_void) {
487 "line %d. %{$FUNCALL} expected %zu, got %zu",
491 if (
func.which_ == ListIds::max_size_void) {
492 std::size_t cur_sz = clst.size ();
495 "line %d. %{$FUNCALL} == %zu, expected res > %zu",
496 __LINE__,
res, cur_sz);
499 if (
func.which_ == ListIds::resize_size_val
500 ||
func.which_ == ListIds::resize_size
501 ||
func.which_ == ListIds::clear_void) {
504 static const int cwidth =
sizeof (
T);
506 const std::size_t got_size = lst.size ();
507 char*
const got =
new char [got_size + 1];
509 std::size_t
index = 0;
510 for (ListCIter it = lst.begin (),
511 end = lst.end (); it !=
end; ++it) {
512 got [
index++] = char (it->data_.val_);
515 got [got_size] =
'\0';
519 "line %d. %{$FUNCALL} expected \"%{X=*}\" "
520 "with length %zu, got %{/*.*Gs} with length %zu",
521 __LINE__, cwidth, int (tdata.
reslen_),
523 1, int (got_size), got, got_size);
525 if (tdata.
reslen_ == got_size) {
533 "line %d. %{$FUNCALL} expected \"%{X=*}\", "
534 "got %{/*.*Gs}, difference at offset %zu",
537 1, int (got_size), got, match);
544#ifndef _RWSTD_NO_EXCEPTIONS
549 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
550 "unexpectedly%{;} caught std::%s(%#s)",
551 __LINE__, 0 != expected, expected,
caught, ex.what ());
556 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
557 "unexpectedly%{;} caught std::%s(%#s)",
558 __LINE__, 0 != expected, expected,
caught, ex.what ());
563 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
564 "unexpectedly%{;} caught %s",
565 __LINE__, 0 != expected, expected,
caught);
573 std::size_t (-1), std::size_t (-1));
593 *pst->throw_at_calls_ [0] = 0;
601int main (
int argc,
char** argv)
607#define TEST(gsig, sig) { \
608 gsig, sig ## _test_cases, \
609 sizeof sig ## _test_cases / sizeof *sig ## _test_cases \
612 TEST (ListIds::size_void, size_void),
613 TEST (ListIds::max_size_void, max_size_void),
614 TEST (ListIds::resize_size_val, resize_size_val),
615 TEST (ListIds::resize_size, resize_size),
616 TEST (ListIds::clear_void, clear_void),
617 TEST (ListIds::empty_void, empty_void)
620 const std::size_t test_count =
sizeof tests /
sizeof *tests;
625 test_capacity_func_array, tests, test_count);
void test_capacity(T *, Allocator *, const ContainerTestCaseData< T > &tdata)
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 rwt_free_store * rwt_get_free_store(rwt_free_store *)
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_