41#define Assign(sig) StringIds::assign_ ## sig
43static const char*
const exceptions[] = {
44 "unknown exception",
"out_of_range",
"length_error",
45 "bad_alloc",
"exception"
56#define TEST(str, arg, res, bthrow) { \
57 __LINE__, -1, -1, -1, -1, -1, \
58 str, sizeof str - 1, \
59 arg, sizeof arg - 1, res, sizeof res - 1, bthrow \
73 TEST (
"ab",
"c",
"c", 0),
76 TEST (
"",
"<U0>",
"", 0),
77 TEST (
"",
"abc",
"abc", 0),
78 TEST (
"abc",
"",
"", 0),
80 TEST (
"<U0>",
"",
"", 0),
81 TEST (
"<U0>",
"a",
"a", 0),
82 TEST (
"<U0>",
"<U0>@2",
"", 0),
84 TEST (
"<U0>@2ab",
"cdefghij",
"cdefghij", 0),
85 TEST (
"a<U0>@2b",
"cdefghij",
"cdefghij", 0),
86 TEST (
"ab<U0>@2",
"cdefghij",
"cdefghij", 0),
87 TEST (
"a<U0>b<U0>@2c",
"e<U0>",
"e", 0),
88 TEST (
"<U0>ab<U0>@2c",
"e<U0>",
"e", 0),
90 TEST (
"",
"x@4096",
"x@4096", 0),
91 TEST (
"x@4096",
"",
"", 0),
92 TEST (
"a@4096",
"b@4096",
"b@4096", 0),
94 TEST (
"",
"x@207",
"x@207", 0),
95 TEST (
"x@128",
"x@207",
"x@207", 0),
96 TEST (
"x@540",
"x@207",
"x@207", 0),
97 TEST (
"",
"x@1412",
"x@1412", 0),
98 TEST (
"x@128",
"x@1412",
"x@1412", 0),
99 TEST (
"x@3695",
"x@1412",
"x@1412", 0),
100 TEST (
"x@872",
"x@873",
"x@873", 0),
101 TEST (
"x@873",
"x@3695",
"x@3695", 0),
104 TEST (
"abc", 0,
"abc", 0),
105 TEST (
"a<U0>@2bc", 0,
"a", 0),
106 TEST (
"<U0>@2abc", 0,
"", 0),
107 TEST (
"abc<U0>@2", 0,
"abc", 0),
108 TEST (
"x@4096", 0,
"x@4096", 0),
110 TEST (
"last",
"test",
"test", 0)
118cstr_test_cases [] = {
121#define TEST(s, arg, res, bthrow) { \
122 __LINE__, -1, -1, -1, -1, -1, \
124 arg, sizeof arg - 1, res, sizeof res - 1, bthrow \
139 TEST (
"ab",
"c",
"c", 0),
141 TEST (
"",
"",
"", 0),
142 TEST (
"",
"<U0>",
"<U0>", 0),
143 TEST (
"",
"abc",
"abc", 0),
144 TEST (
"abc",
"",
"", 0),
146 TEST (
"<U0>",
"",
"", 0),
147 TEST (
"<U0>",
"a",
"a", 0),
148 TEST (
"<U0>",
"<U0>@2",
"<U0>@2", 0),
150 TEST (
"ab",
"c<U0>e",
"c<U0>e", 0),
152 TEST (
"<U0>@2ab",
"cdefghij",
"cdefghij", 0),
153 TEST (
"a<U0>@2b",
"cdefghij",
"cdefghij", 0),
154 TEST (
"ab<U0>@2",
"cdefghij",
"cdefghij", 0),
155 TEST (
"a<U0>b<U0>@2c",
"e<U0>",
"e<U0>", 0),
156 TEST (
"<U0>ab<U0>@2c",
"e<U0>",
"e<U0>", 0),
157 TEST (
"ab<U0>@2c<U0>",
"<U0>e",
"<U0>e", 0),
159 TEST (
"e<U0>",
"a<U0>b<U0>@2c",
"a<U0>b<U0>@2c", 0),
160 TEST (
"e<U0>@2",
"<U0>ab<U0>@2c",
"<U0>ab<U0>@2c", 0),
161 TEST (
"<U0>e",
"ab<U0>@2c<U0>",
"ab<U0>@2c<U0>", 0),
163 TEST (
"",
"x@4096",
"x@4096", 0),
164 TEST (
"x@4096",
"",
"", 0),
165 TEST (
"a@4096",
"b@4096",
"b@4096", 0),
167 TEST (
"",
"x@207",
"x@207", 0),
168 TEST (
"x@128",
"x@207",
"x@207", 0),
169 TEST (
"x@540",
"x@207",
"x@207", 0),
170 TEST (
"",
"x@1412",
"x@1412", 0),
171 TEST (
"x@128",
"x@1412",
"x@1412", 0),
172 TEST (
"x@3695",
"x@1412",
"x@1412", 0),
173 TEST (
"x@872",
"x@873",
"x@873", 0),
174 TEST (
"x@873",
"x@3695",
"x@3695", 0),
177 TEST (
"abc", 0,
"abc", 0),
178 TEST (
"a<U0>@2bc", 0,
"a<U0>@2bc", 0),
179 TEST (
"<U0>@2abc", 0,
"<U0>@2abc", 0),
180 TEST (
"abc<U0>@2", 0,
"abc<U0>@2", 0),
181 TEST (
"x@4096", 0,
"x@4096", 0),
183 TEST (
"last",
"test",
"test", 0)
191cptr_size_test_cases [] = {
194#define TEST(str, arg, size, res, bthrow) { \
195 __LINE__, -1, size, -1, -1, -1, \
196 str, sizeof str - 1, \
197 arg, sizeof arg - 1, res, sizeof res - 1, bthrow \
212 TEST (
"ab",
"c", 1,
"c", 0),
214 TEST (
"",
"", 0,
"", 0),
215 TEST (
"",
"abc", 1,
"a", 0),
216 TEST (
"",
"<U0>", 1,
"<U0>", 0),
218 TEST (
"<U0>",
"", 0,
"", 0),
219 TEST (
"<U0>",
"a", 0,
"", 0),
220 TEST (
"<U0>",
"a", 1,
"a", 0),
221 TEST (
"<U0>",
"<U0>@2", 1,
"<U0>", 0),
222 TEST (
"<U0>",
"<U0>@2", 2,
"<U0>@2", 0),
224 TEST (
"cde",
"ab", 2,
"ab", 0),
225 TEST (
"cde",
"ab", 1,
"a", 0),
227 TEST (
"<U0>e<U0>",
"a<U0>b<U0>@2c", 0,
"", 0),
228 TEST (
"<U0>e<U0>",
"<U0>ab<U0>@2c", 3,
"<U0>ab", 0),
229 TEST (
"<U0>e<U0>",
"a<U0>b<U0>@2c", 6,
"a<U0>b<U0>@2c", 0),
231 TEST (
"a<U0>b<U0>@2c",
"<U0>e<U0>", 3,
"<U0>e<U0>", 0),
232 TEST (
"a<U0>b<U0>@2c",
"<U0>@2e<U0>", 2,
"<U0>@2", 0),
233 TEST (
"<U0>ab<U0>@2c",
"<U0>e<U0>", 1,
"<U0>", 0),
234 TEST (
"a<U0>bc<U0>@2",
"<U0>e", 2,
"<U0>e", 0),
236 TEST (
"", 0, 0,
"", 0),
237 TEST (
"abc", 0, 0,
"", 0),
238 TEST (
"abc", 0, 1,
"a", 0),
239 TEST (
"abc", 0, 2,
"ab", 0),
240 TEST (
"a<U0>bc", 0, 2,
"a<U0>", 0),
241 TEST (
"<U0>abc<U0>@2", 0, 1,
"<U0>", 0),
242 TEST (
"a<U0>bc<U0>@2", 0, 3,
"a<U0>b", 0),
243 TEST (
"a<U0>bc<U0>@2", 0, 6,
"a<U0>bc<U0>@2", 0),
244 TEST (
"x@4096", 0, 2048,
"x@2048", 0),
246 TEST (
"",
"x@4096", 4096,
"x@4096", 0),
247 TEST (
"abcd",
"x@4096", 0,
"", 0),
248 TEST (
"x@4096",
"x@4096", 0,
"", 0),
249 TEST (
"x@4096",
"x@4096", 1,
"x", 0),
250 TEST (
"x@4096",
"", 0,
"", 0),
251 TEST (
"a@4096",
"b@4096", 2048,
"b@2048", 0),
253 TEST (
"",
"x@207", 207,
"x@207", 0),
254 TEST (
"x@128",
"x@334", 207,
"x@207", 0),
255 TEST (
"x@540",
"x@207", 128,
"x@128", 0),
256 TEST (
"",
"x@1412", 873,
"x@873", 0),
257 TEST (
"x@128",
"x@1412", 1412,
"x@1412", 0),
258 TEST (
"x@3695",
"x@1412", 540,
"x@540", 0),
259 TEST (
"x@872",
"x@873", 873,
"x@873", 0),
260 TEST (
"x@873",
"x@3695", 2284,
"x@2284", 0),
262 TEST (
"",
"", -1,
"", 2),
264 TEST (
"last",
"test", 4,
"test", 0)
276#define cstr_size_size_test_cases range_test_cases
279#define TEST(str, arg, off, size, res, bthrow) { \
280 __LINE__, -1, -1, off, size, -1, \
281 str, sizeof str - 1, \
282 arg, sizeof arg - 1, res, sizeof res - 1, bthrow \
298 TEST (
"ab",
"c", 0, 1,
"c", 0),
300 TEST (
"",
"", 0, 0,
"", 0),
301 TEST (
"",
"abc", 1, 1,
"b", 0),
302 TEST (
"",
"<U0>", 0, 1,
"<U0>", 0),
304 TEST (
"<U0>",
"", 0, 0,
"", 0),
306 TEST (
"abc",
"", 0, 0,
"", 0),
308 TEST (
"<U0>",
"a", 0, 1,
"a", 0),
309 TEST (
"<U0>",
"<U0>@2", 1, 1,
"<U0>", 0),
310 TEST (
"<U0>",
"<U0>@2", 0, 2,
"<U0>@2", 0),
311 TEST (
"<U0>",
"<U0>@2", 1, 5,
"<U0>", 0),
313 TEST (
"cde",
"ab", 0, 2,
"ab", 0),
314 TEST (
"cde",
"ab", 0, 1,
"a", 0),
315 TEST (
"cde",
"ab", 1, 5,
"b", 0),
317 TEST (
"ab",
"c<U0>e", 0, 3,
"c<U0>e", 0),
318 TEST (
"ab",
"c<U0>e", 1, 2,
"<U0>e", 0),
319 TEST (
"ab",
"c<U0>e", 0, 2,
"c<U0>", 0),
321 TEST (
"<U0>e<U0>",
"<U0>ab<U0>@2c", 0, 9,
"<U0>ab<U0>@2c", 0),
322 TEST (
"<U0>e<U0>",
"<U0>ab<U0>@2c", 0, 3,
"<U0>ab", 0),
323 TEST (
"a<U0>b<U0>@2c",
"<U0>e<U0>", 0, 3,
"<U0>e<U0>", 0),
324 TEST (
"a<U0>b<U0>@2c",
"<U0>@2e<U0>", 0, 2,
"<U0>@2", 0),
325 TEST (
"<U0>ab<U0>@2c",
"<U0>e<U0>", 2, 1,
"<U0>", 0),
326 TEST (
"<U0>ab<U0>@2c",
"<U0>e<U0>", 2, 9,
"<U0>", 0),
327 TEST (
"a<U0>bc<U0>@2",
"<U0>e", 0, 2,
"<U0>e", 0),
329 TEST (
"", 0, 0, 0,
"", 0),
330 TEST (
"abc", 0, 1, 0,
"", 0),
331 TEST (
"abc", 0, 1, 1,
"b", 0),
332 TEST (
"abc", 0, 0, 2,
"ab", 0),
333 TEST (
"a<U0>bc<U0>@2", 0, 4, 2,
"<U0>@2", 0),
334 TEST (
"a<U0>bc<U0>@2", 0, 1, 3,
"<U0>bc", 0),
335 TEST (
"a<U0>bc<U0>@2", 0, 0, 9,
"a<U0>bc<U0>@2", 0),
336 TEST (
"abcdef", 0, 1, 2,
"bc", 0),
337 TEST (
"x@4096", 0, 1, 2,
"xx", 0),
339 TEST (
"x@4096",
"", 0, 0,
"", 0),
340 TEST (
"",
"x@4096", 9, 2,
"xx", 0),
341 TEST (
"",
"x@4096", 9, 0,
"", 0),
342 TEST (
"abc",
"x@4096", 2, 1,
"x", 0),
343 TEST (
"x@4096",
"x@4096", 2, 3,
"xxx", 0),
344 TEST (
"",
"x@4096", 0, 4096,
"x@4096", 0),
345 TEST (
"",
"x@4096", 100, 2000,
"x@2000", 0),
347 TEST (
"",
"x@207", 0, 207,
"x@207", 0),
348 TEST (
"x@128",
"x@334", 10, 207,
"x@207", 0),
349 TEST (
"x@540",
"x@207", 50, 128,
"x@128", 0),
350 TEST (
"",
"x@1412", 128, 873,
"x@873", 0),
351 TEST (
"x@128",
"x@1412", 0, 1412,
"x@1412", 0),
352 TEST (
"x@3695",
"x@1412", 207, 540,
"x@540", 0),
353 TEST (
"x@872",
"x@874", 1, 873,
"x@873", 0),
354 TEST (
"x@873",
"x@3695", 10, 2284,
"x@2284", 0),
356 TEST (
"",
"<U0>", 2, 0,
"", 1),
357 TEST (
"",
"a", 2, 0,
"", 1),
358 TEST (
"",
"x@4096", 4106, 0,
"", 1),
360 TEST (
"last",
"test", 0, 4,
"test", 0)
368size_val_test_cases [] = {
371#define TEST(str, size, val, res, bthrow) { \
372 __LINE__, -1, size, -1, -1, val, \
373 str, sizeof str - 1, \
374 0, 0, res, sizeof res - 1, bthrow \
389 TEST (
"ab", 1,
'c',
"c", 0),
391 TEST (
"", 0,
' ',
"", 0),
392 TEST (
"", 1,
'b',
"b", 0),
393 TEST (
"", 3,
'b',
"bbb", 0),
395 TEST (
"<U0>", 0,
' ',
"", 0),
396 TEST (
"", 2,
'\0',
"<U0>@2", 0),
398 TEST (
"<U0>", 1,
'a',
"a", 0),
399 TEST (
"<U0>", 1,
'\0',
"<U0>", 0),
400 TEST (
"<U0>", 2,
'\0',
"<U0>@2", 0),
401 TEST (
"<U0>", 0,
'\0',
"", 0),
403 TEST (
"cde", 3,
'a',
"aaa", 0),
404 TEST (
"ab", 2,
'\0',
"<U0>@2", 0),
405 TEST (
"ab", 1,
'\0',
"<U0>", 0),
407 TEST (
"a<U0>b<U0>@2c", 2,
'\0',
"<U0>@2", 0),
408 TEST (
"a<U0>b<U0>@2c", 1,
'\0',
"<U0>", 0),
409 TEST (
"<U0>ab<U0>@2c", 3,
'\0',
"<U0>@3", 0),
410 TEST (
"a<U0>bc<U0>@2", 2,
'a',
"aa", 0),
412 TEST (
"", 4096,
'x',
"x@4096", 0),
413 TEST (
"x@4096", 0,
'x',
"", 0),
415 TEST (
"x@127", 128,
'x',
"x@128", 0),
416 TEST (
"x@200", 207,
'x',
"x@207", 0),
417 TEST (
"x@334", 128,
'x',
"x@128", 0),
418 TEST (
"", 540,
'x',
"x@540", 0),
419 TEST (
"xx", 873,
'x',
"x@873", 0),
420 TEST (
"x@873", 1412,
'x',
"x@1412", 0),
421 TEST (
"x@3695", 207,
'x',
"x@207", 0),
422 TEST (
"x@540", 3695,
'x',
"x@3695", 0),
424 TEST (
"", -1,
'x',
"", 2),
426 TEST (
"last", 4,
't',
"tttt", 0)
433template <
class String,
class Iterator>
460 return str.assign (first,
last);
468template <
class String,
class Iterator>
485 const std::size_t srclen_ = tcase.
arg ? tdata.
arglen_ :
str.size ();
487 const std::size_t
off =
489 const std::size_t ext = tdata.
ext2_;
491 if (0 == tcase.
arg) {
498 return str.assign (first,
last);
506 return str.assign (first,
last);
512template <
class charT,
class Traits,
class Allocator>
514 std::basic_string <charT, Traits, Allocator> > &rng,
517 typedef std::basic_string <charT, Traits, Allocator>
String;
518 typedef typename String::iterator StringIter;
530 std::size_t size2 = tcase.
size2 >= 0 ? tcase.
size2 :
str.max_size () + 1;
538 const charT*
const arg_ptr = tcase.
arg ?
arg.c_str () :
str.c_str ();
541 std::size_t total_length_calls = 0;
542 std::size_t n_length_calls = 0;
546 total_length_calls = rg_calls [TraitsFunc::length];
554 std::size_t throw_count;
555 for (throw_count = 0; ; ++throw_count) {
558 const char* expected = 0;
561#ifndef _RWSTD_NO_EXCEPTIONS
564 expected = exceptions [1];
565 else if (2 == tcase.
bthrow)
566 expected = exceptions [2];
567 else if (0 == tcase.
bthrow) {
571 expected = exceptions [3];
588 const String* ret_ptr = 0;
594 switch (
func.which_) {
597 ret_ptr = &
str.assign (arg_ptr);
599 n_length_calls = rg_calls [TraitsFunc::length];
603 ret_ptr = &
str.assign (arg_str);
607 ret_ptr = &
str.assign (arg_ptr,
size);
610 case Assign (cstr_size_size):
611 ret_ptr = &
str.assign (arg_str, tcase.
off2, size2);
621 ret_ptr = &rng (
str, tdata);
625 RW_ASSERT (!
"test logic error: unknown assign overload");
631 const std::ptrdiff_t ret_off = ret_ptr - &
str;
635 "line %d. %{$FUNCALL} returned invalid reference, "
636 "offset is %td", __LINE__, ret_off);
639 static const int cwidth =
sizeof (
charT);
643 "line %d. %{$FUNCALL}: expected %{/*.*Gs} with length "
644 "%zu, got %{/*.*Gs} with length %zu", __LINE__,
646 cwidth, int (
str.size ()),
str.c_str (),
str.size ());
652 const std::size_t match =
656 "line %d. %{$FUNCALL}: expected %{/*.*Gs}, "
657 "got %{/*.*Gs}, difference at off %zu",
659 cwidth, int (
str.size ()),
str.c_str (), match);
663 if (
Assign (cptr) ==
func.which_ && rg_calls) {
664 rw_assert (n_length_calls - total_length_calls > 0,
665 0, tcase.
line,
"line %d. %{$FUNCALL} doesn't "
666 "use traits::length()", __LINE__);
670#ifndef _RWSTD_NO_EXCEPTIONS
672 catch (
const std::out_of_range &ex) {
675 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
676 "unexpectedly%{;} caught std::%s(%#s)",
677 __LINE__, 0 != expected, expected,
caught, ex.what ());
679 catch (
const std::length_error &ex) {
682 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
683 "unexpectedly%{;} caught std::%s(%#s)",
684 __LINE__, 0 != expected, expected,
caught, ex.what ());
689 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
690 "unexpectedly%{;} caught std::%s(%#s)",
691 __LINE__, 0 != expected, expected,
caught, ex.what ());
696 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
697 "unexpectedly%{;} caught std::%s(%#s)",
698 __LINE__, 0 != expected, expected,
caught, ex.what ());
703 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
704 "unexpectedly%{;} caught %s",
705 __LINE__, 0 != expected, expected,
caught);
713 std::size_t (-1), std::size_t (-1));
728 else if (0 < tcase.
bthrow) {
730 "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
731 "%{:}unexpectedly caught %s%{;}",
738 std::size_t expect_throws = 0;
740#ifndef _RWSTD_NO_STRING_REF_COUNT
744#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
757#ifndef _RWSTD_NO_STRING_REF_COUNT
765 "line %d: %{$FUNCALL}: expected exactly 1 %s exception "
766 "while changing capacity from %zu to %zu, got %zu",
767 __LINE__, exceptions [3],
771 "line %d: %{$FUNCALL}: expected at least 1 %s exception "
772 "while changing capacity from %zu to %zu, got %zu",
773 __LINE__, exceptions [3],
783template <
class charT,
class Traits,
class Allocator>
787 typedef std::basic_string<charT, Traits, Allocator>
String;
796#define TEST(Iterator) do { \
797 typedef typename String::Iterator Iter; \
799 AssignRangeOverload<String, Iter> rng; \
800 test_assign ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata); \
816#define TEST(Iterator) do { \
817 typedef Iterator<charT> Iter; \
819 AssignRange<String, Iter> rng; \
820 test_assign ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata); \
829 rw_error (0, 0, __LINE__,
"bad iterator id");
843int main (
int argc,
char** argv)
850 Assign (sig), sig ## _test_cases, \
851 sizeof sig ## _test_cases / sizeof *sig ## _test_cases \
857 TEST (cstr_size_size),
862 const std::size_t test_count =
sizeof tests /
sizeof *tests;
867 test_assign_func_array, tests, test_count);
#define TEST(str, arg, res, bthrow)
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)
UserChar make_char(char c, UserChar *)
_RWSTD_SIZE_T * rw_get_call_counters(std::char_traits< charT > *, charT *)
_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 int rw_error(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)
String::value_type StringChar
virtual List & operator()(List &lst, const ContainerTestCaseData< ListVal > &tdata) const
String::iterator StringIter
String::value_type StringChar
virtual List & operator()(List &lst, const ContainerTestCaseData< ListVal > &tdata) const
String::iterator StringIter
static ContIter begin(List &cont, ContIter *)
static SharedAlloc * instance(SharedAlloc *=0)
_RWSTD_SIZE_T throw_at_calls_[n_funs]
StringIds::OverloadId which_
StringIds::IteratorId iter_id_
int assert_equal(const StringState &, int, int, const char *) const
_RWSTD_SIZE_T * throw_at_calls_[2]
_RWSTD_SIZE_T new_calls_[2]