38static const char*
const exceptions[] = {
39 "unknown exception",
"bad_alloc",
"exception"
47begin_void_test_cases [] = {
50#define TEST(lst, res) { \
51 __LINE__, -1, -1, -1, -1, -1, \
52 lst, sizeof (lst) - 1, \
60 TEST (
"", _RWSTD_SIZE_MAX),
64 TEST (
"<U0>ab<U0>@2c",
'\0'),
65 TEST (
"a<U0>b<U0>@2c",
'a' ),
66 TEST (
"a<U0>bc<U0>@2",
'a' ),
67 TEST (
"x@4096",
'x' ),
76end_void_test_cases [] = {
79#define TEST(lst, res) { \
80 __LINE__, -1, -1, -1, -1, -1, \
81 lst, sizeof (lst) - 1, \
89 TEST (
"", _RWSTD_SIZE_MAX),
93 TEST (
"<U0>ab<U0>@2c",
'c' ),
94 TEST (
"a<U0>b<U0>@2c",
'c' ),
95 TEST (
"a<U0>bc<U0>@2",
'\0'),
96 TEST (
"x@4096",
'x' ),
105get_allocator_void_test_cases [] = {
109 __LINE__, -1, -1, -1, -1, -1, \
110 lst, sizeof (lst) - 1, \
128 TEST (
"a@2048cb@2047" ),
135template <
class T,
class Allocator>
139 typedef std::list <T, Allocator> List;
140 typedef typename List::iterator ListIter;
141 typedef typename List::const_iterator ListCIter;
142 typedef typename List::reverse_iterator ListRIter;
143 typedef typename List::const_reverse_iterator ListCRIter;
149 const bool test_iters =
150 func.which_ == ListIds::begin_void
151 ||
func.which_ == ListIds::begin_const_void
152 ||
func.which_ == ListIds::end_void
153 ||
func.which_ == ListIds::end_const_void
154 ||
func.which_ == ListIds::rbegin_void
155 ||
func.which_ == ListIds::rbegin_const_void
156 ||
func.which_ == ListIds::rend_void
157 ||
func.which_ == ListIds::rend_const_void
158 ||
func.which_ == ListIds::front_void
159 ||
func.which_ == ListIds::front_const_void
160 ||
func.which_ == ListIds::back_void
161 ||
func.which_ == ListIds::back_const_void;
163 const bool test_const_list =
164 func.which_ == ListIds::begin_const_void
165 ||
func.which_ == ListIds::end_const_void
166 ||
func.which_ == ListIds::rbegin_const_void
167 ||
func.which_ == ListIds::rend_const_void
168 ||
func.which_ == ListIds::front_const_void
169 ||
func.which_ == ListIds::back_const_void;
171 const bool test_end_iters =
172 func.which_ == ListIds::end_void
173 ||
func.which_ == ListIds::end_const_void
174 ||
func.which_ == ListIds::rend_void
175 ||
func.which_ == ListIds::rend_const_void;
185 const std::size_t s_size = test_const_list ? clst.size () : lst.size ();
198 const T* res_ptr = 0;
212 bool it_relations =
true;
214 switch (
func.which_) {
216 case ListIds::begin_void:
218 it_relations = it == lst.rend ().base ();
219 if (s_size) res_ptr = &*it;
222 case ListIds::begin_const_void:
224 it_relations = cit == clst.rend ().base ();
225 if (s_size) res_ptr = &*cit;
228 case ListIds::end_void:
230 it_relations = it == lst.rbegin ().base ();
231 if (s_size) res_ptr = &*--it;
234 case ListIds::end_const_void:
236 it_relations = cit == clst.rbegin ().base ();
237 if (s_size) res_ptr = &*--cit;
240 case ListIds::rbegin_void:
242 it_relations = rit.base () == lst.end ();
243 if (s_size) res_ptr = &*rit;
246 case ListIds::rbegin_const_void:
247 crit = clst.rbegin();
248 it_relations = crit.base () == clst.end ();
249 if (s_size) res_ptr = &*crit;
252 case ListIds::rend_void:
254 it_relations = rit.base () == lst.begin ();
255 if (s_size) res_ptr = &*--rit;
258 case ListIds::rend_const_void:
260 it_relations = crit.base () == clst.begin ();
261 if (s_size) res_ptr = &*--crit;
264 case ListIds::front_void:
266 res_ptr = &lst.front ();
267 it_relations = res_ptr == &*lst.begin ();
271 case ListIds::front_const_void:
273 res_ptr = &clst.front ();
274 it_relations = res_ptr == &*clst.begin ();
278 case ListIds::back_void:
280 res_ptr = &lst.back ();
281 it_relations = res_ptr == &*--lst.end ();
285 case ListIds::back_const_void:
287 res_ptr = &clst.back ();
288 it_relations = res_ptr == &*--clst.end ();
292 case ListIds::get_allocator_void:
293 resalloc = clst.get_allocator ();
297 RW_ASSERT (!
"test logic error: unknown iterators overload");
304 (_RWSTD_SIZE_MAX != tcase.
nres ? char (tcase.
nres) : char ());
306 const bool success = 0 == T::mismatch (res_ptr, &exp_res, 1);
309 "line %d. %{$FUNCALL}%{?} - 1%{;} expected "
310 "%{#c}, got %{#c}", __LINE__,
311 test_end_iters, exp_res, char (res_ptr->data_.val_));
320 if (
func.which_ == ListIds::begin_void
321 ||
func.which_ == ListIds::end_void)
322 success = it == lst.begin () && it == lst.end ();
324 if (
func.which_ == ListIds::begin_const_void
325 ||
func.which_ == ListIds::end_const_void)
326 success = cit == clst.begin () && cit == clst.end ();
328 if (
func.which_ == ListIds::rbegin_void
329 ||
func.which_ == ListIds::rend_void)
330 success = rit == lst.rbegin () && rit == lst.rend ();
332 if (
func.which_ == ListIds::rbegin_const_void
333 ||
func.which_ == ListIds::rend_const_void)
334 success = crit == clst.rbegin () && crit == clst.rend ();
338 "line %d. %{$FUNCALL} returned iterator is not "
339 "equal to begin and end for an empty list",
345 "line %d. %{$FUNCALL} iterators "
346 "relationship is broken", __LINE__);
349 if (
func.which_ == ListIds::get_allocator_void) {
353 const bool success = (
alloc == resalloc);
356 "line %d. %{$FUNCALL} expected equal to allocator "
357 "passed to the ctor", __LINE__);
361#ifndef _RWSTD_NO_EXCEPTIONS
365 "line %d. %{$FUNCALL} unexpectedly caught std::%s(%#s)",
366 __LINE__, exceptions [1], ex.what ());
370 "line %d. %{$FUNCALL} unexpectedly caught std::%s(%#s)",
371 __LINE__, exceptions [2], ex.what ());
375 "line %d. %{$FUNCALL} unexpectedly caught %s",
376 __LINE__, exceptions [0]);
384 std::size_t (-1), std::size_t (-1));
388 __LINE__, tcase.
line,
"call");
395int main (
int argc,
char** argv)
401#define TEST(gsig, sig) { \
402 gsig, sig ## _test_cases, \
403 sizeof sig ## _test_cases / sizeof *sig ## _test_cases \
406 TEST (ListIds::begin_void, begin_void),
407 TEST (ListIds::begin_const_void, begin_void),
408 TEST (ListIds::end_void, end_void),
409 TEST (ListIds::end_const_void, end_void),
410 TEST (ListIds::rbegin_void, end_void),
411 TEST (ListIds::rbegin_const_void, end_void),
412 TEST (ListIds::rend_void, begin_void),
413 TEST (ListIds::rend_const_void, begin_void),
414 TEST (ListIds::front_void, begin_void),
415 TEST (ListIds::front_const_void, begin_void),
416 TEST (ListIds::back_void, end_void),
417 TEST (ListIds::back_const_void, end_void),
418 TEST (ListIds::get_allocator_void, get_allocator_void)
421 const std::size_t test_count =
sizeof tests /
sizeof *tests;
425 test_iterators_func_array, tests, test_count);
void test_iterators(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 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 *,...)
void assert_equal(const ListState &state, int line, int case_line, const char *when) const