41static const char*
const exceptions[] = {
42 "unknown exception",
"bad_alloc",
"exception"
50begin_void_test_cases [] = {
53#define TEST(str, res) { \
54 __LINE__, -1, -1, -1, -1, -1, \
55 str, sizeof (str) - 1, \
66 TEST (
"<U0>ab<U0>@2c",
'\0'),
67 TEST (
"a<U0>b<U0>@2c",
'a' ),
68 TEST (
"a<U0>bc<U0>@2",
'a' ),
69 TEST (
"x@4096",
'x' ),
78end_void_test_cases [] = {
81#define TEST(str, res) { \
82 __LINE__, -1, -1, -1, -1, -1, \
83 str, sizeof (str) - 1, \
94 TEST (
"<U0>ab<U0>@2c",
'c' ),
95 TEST (
"a<U0>b<U0>@2c",
'c' ),
96 TEST (
"a<U0>bc<U0>@2",
'\0'),
97 TEST (
"x@4096",
'x' ),
106c_str_void_test_cases [] = {
110 __LINE__, -1, -1, -1, -1, -1, \
111 str, sizeof (str) - 1, 0, 0, \
112 str, sizeof (str) - 1, 0 \
130 TEST (
"abcdefghij" ),
133 TEST (
"abbdefghij" ),
134 TEST (
"abcdeeghij" ),
135 TEST (
"abcdefghii" ),
137 TEST (
"bbcdefghij" ),
138 TEST (
"eeeeeeghij" ),
142 TEST (
"bbcdefghij" ),
143 TEST (
"abcdffghij" ),
144 TEST (
"abcdefghjj" ),
146 TEST (
"a<U0>b<U0>@2c" ),
148 TEST (
"<U0>ab<U0>@2c" ),
157 TEST (
"a@2048b@2048" ),
158 TEST (
"a@2048cb@2047" ),
168get_allocator_void_test_cases [] = {
172 __LINE__, -1, -1, -1, -1, -1, \
173 str, sizeof (str) - 1, \
191 TEST (
"a@2048cb@2047" ),
198template <
class charT,
class Traits,
class Allocator>
202 typedef std::basic_string <charT, Traits, Allocator>
String;
203 typedef typename String::iterator StringIter;
204 typedef typename String::const_iterator StringCIter;
205 typedef typename String::reverse_iterator StringRIter;
206 typedef typename String::const_reverse_iterator StringCRIter;
211 const bool test_iters =
func.which_ == StringIds::begin_void
212 ||
func.which_ == StringIds::begin_const_void
213 ||
func.which_ == StringIds::end_void
214 ||
func.which_ == StringIds::end_const_void
215 ||
func.which_ == StringIds::rbegin_void
216 ||
func.which_ == StringIds::rbegin_const_void
217 ||
func.which_ == StringIds::rend_void
218 ||
func.which_ == StringIds::rend_const_void;
220 const bool test_const_iters =
func.which_ == StringIds::begin_const_void
221 ||
func.which_ == StringIds::end_const_void
222 ||
func.which_ == StringIds::rbegin_const_void
223 ||
func.which_ == StringIds::rend_const_void;
225 const bool test_end_iters =
func.which_ == StringIds::end_void
226 ||
func.which_ == StringIds::end_const_void
227 ||
func.which_ == StringIds::rend_void
228 ||
func.which_ == StringIds::rend_const_void;
238 const std::size_t s_size = test_const_iters ? cstr.size () :
str.size ();
251 std::size_t throw_count;
252 for (throw_count = 0; ; ++throw_count) {
255 const char* expected = 0;
258#ifndef _RWSTD_NO_EXCEPTIONS
263 expected = exceptions [1];
274 const charT* ret_ptr = 0;
293 bool it_relations =
true;
295 switch (
func.which_) {
297 case StringIds::begin_void:
300 it_relations = it ==
str.rend ().base ();
303 case StringIds::begin_const_void:
306 it_relations = cit == cstr.rend ().base ();
309 case StringIds::end_void:
311 res = s_size ? *(it - 1) :
charT ();
312 it_relations = it ==
str.rbegin ().base ();
315 case StringIds::end_const_void:
317 res = s_size ? *(cit - 1) :
charT ();
318 it_relations = cit == cstr.rbegin ().base ();
321 case StringIds::rbegin_void:
324 it_relations = rit.base () ==
str.end ();
327 case StringIds::rbegin_const_void:
328 crit = cstr.rbegin();
330 it_relations = crit.base () == cstr.end ();
333 case StringIds::rend_void:
335 res = s_size ? *(rit - 1) :
charT ();
336 it_relations = rit.base () ==
str.begin ();
339 case StringIds::rend_const_void:
341 res = s_size ? *(crit - 1) :
charT ();
342 it_relations = crit.base () == cstr.begin ();
345 case StringIds::c_str_void:
346 ret_ptr = cstr.c_str ();
349 case StringIds::data_void:
350 ret_ptr = cstr.data ();
353 case StringIds::get_allocator_void:
354 resalloc = cstr.get_allocator ();
358 RW_ASSERT (
"test logic error: unknown iterators overload");
363 static const int cwidth =
sizeof (
charT);
365 if (
func.which_ == StringIds::data_void
366 ||
func.which_ == StringIds::c_str_void) {
371 "line %d. %{$FUNCALL} expected non null, got null",
385 const std::size_t match =
389 "line %d. %{$FUNCALL} expected %{#*s}, "
390 "got %{/*.*Gs}, differ at pos %zu",
392 cwidth, int (s_size), ret_ptr, match);
394 if (
func.which_ == StringIds::c_str_void) {
397 const char null = char ();
399 (1 ==
rw_match (&null, &ret_ptr[s_size], 1));
402 "line %d. %{$FUNCALL} expected last element "
403 "is a null character %{#c}, got %{#c}",
404 __LINE__, null, ret_ptr[s_size]);
416 const bool success = (1 ==
rw_match (&exp_res, &
res, 1));
419 "line %d. %{$FUNCALL}%{?} - 1%{;} expected "
420 "%{#c}, got %{#c}", __LINE__,
421 test_end_iters, exp_res,
res);
426 if (
func.which_ == StringIds::begin_void
427 ||
func.which_ == StringIds::end_void)
428 success = it ==
str.begin () && it ==
str.end ();
430 if (
func.which_ == StringIds::begin_const_void
431 ||
func.which_ == StringIds::end_const_void)
432 success = cit == cstr.begin () && cit == cstr.end ();
434 if (
func.which_ == StringIds::rbegin_void
435 ||
func.which_ == StringIds::rend_void)
436 success = rit ==
str.rbegin () && rit ==
str.rend ();
438 if (
func.which_ == StringIds::rbegin_const_void
439 ||
func.which_ == StringIds::rend_const_void)
441 crit == cstr.rbegin () && crit == cstr.rend ();
445 "line %d. %{$FUNCALL} returned iterator is not "
446 "equal to begin and end for an empty string",
452 "line %d. %{$FUNCALL} iterators "
453 "relationship is broken", __LINE__);
456 if (
func.which_ == StringIds::get_allocator_void) {
460 const bool success = (
alloc == resalloc);
463 "line %d. %{$FUNCALL} expected equal to allocator "
464 "passed to the ctor", __LINE__);
468#ifndef _RWSTD_NO_EXCEPTIONS
473 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
474 "unexpectedly%{;} caught std::%s(%#s)",
475 __LINE__, 0 != expected, expected,
caught, ex.what ());
480 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
481 "unexpectedly%{;} caught std::%s(%#s)",
482 __LINE__, 0 != expected, expected,
caught, ex.what ());
487 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
488 "unexpectedly%{;} caught %s",
489 __LINE__, 0 != expected, expected,
caught);
497 std::size_t (-1), std::size_t (-1));
515 "line %d: %{$FUNCALL}: expected 0 %s exceptions, got %zu",
516 __LINE__, exceptions [1], throw_count);
527int main (
int argc,
char** argv)
533#define TEST(gsig, sig) { \
534 gsig, sig ## _test_cases, \
535 sizeof sig ## _test_cases / sizeof *sig ## _test_cases \
538 TEST (StringIds::begin_void, begin_void),
539 TEST (StringIds::begin_const_void, begin_void),
540 TEST (StringIds::end_void, end_void),
541 TEST (StringIds::end_const_void, end_void),
542 TEST (StringIds::rbegin_void, end_void),
543 TEST (StringIds::rbegin_const_void, end_void),
544 TEST (StringIds::rend_void, begin_void),
545 TEST (StringIds::rend_const_void, begin_void),
546 TEST (StringIds::c_str_void, c_str_void),
547 TEST (StringIds::data_void, c_str_void),
548 TEST (StringIds::get_allocator_void, get_allocator_void)
551 const std::size_t test_count =
sizeof tests /
sizeof *tests;
554 "lib.string.iterators",
555 test_iterators_func_array, tests, test_count);
void test_iterators(charT *, Traits *, Allocator *, const StringTestCaseData< charT > &tdata)
std::char_traits< S > Traits
const StringTestCase & 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_assert(int, const char *, int, const char *,...)
_TEST_EXPORT rwt_free_store * rwt_get_free_store(rwt_free_store *)
StringState rw_get_string_state(const String &str)
_TEST_EXPORT int rw_run_string_test(int, char **, const char *, const char *, StringTestFunc *, const StringTest *, _RWSTD_SIZE_T)
#define DEFINE_STRING_TEST_FUNCTIONS(fname)
static SharedAlloc * instance(SharedAlloc *=0)
_RWSTD_SIZE_T throw_at_calls_[n_funs]
int assert_equal(const StringState &, int, int, const char *) const
_RWSTD_SIZE_T * throw_at_calls_[2]
_RWSTD_SIZE_T new_calls_[2]