42#define Swap(sig) StringIds::swap_ ## sig
44static const char*
const exceptions[] = {
45 "unknown exception",
"out_of_range",
"length_error",
46 "bad_alloc",
"exception"
57#define TEST(str, arg) \
58 { __LINE__, -1, -1, -1, -1, -1, \
59 str, sizeof str - 1, arg, sizeof arg - 1, \
77 TEST (
"a<U0>b<U0>@2c",
"<U0>b<U0>@2c"),
78 TEST (
"<U0>b<U0>@2c",
"a<U0>b<U0>@2c"),
80 TEST (
"a<U0>b<U0>@2c",
"<U0>@2"),
81 TEST (
"<U0>@2",
"a<U0>b<U0>@2c"),
85 TEST (
"x@4096",
"<U0>@3"),
86 TEST (
"<U0>@3",
"x@4096"),
87 TEST (
"x@4096",
"x@4096"),
90 TEST (
"x@207",
"x@128"),
91 TEST (
"x@128",
"x@334"),
92 TEST (
"x@873",
"x@334"),
93 TEST (
"x@1412",
"x@540"),
94 TEST (
"x@540",
"x@2284"),
95 TEST (
"x@3695",
"x@2284"),
96 TEST (
"x@3695",
"x@128"),
101 TEST (
"a<U0>b<U0>@2c", 0),
106 TEST (0,
"abc@1024"),
107 TEST (0,
"a<U0>b<U0>@2c"),
110 TEST (
"last",
"test")
116template <
class charT,
class Traits,
class Allocator>
122 typedef std::basic_string <charT, Traits, Allocator>
String;
132 const charT*
const p1 = s_str.data ();
133 const charT*
const p2 = tcase.
arg ? s_arg.data () : s_str.data ();
135 const char*
const src = tcase.
arg ? tcase.
arg : tcase.
str;
138 String& arg_str = tcase.
arg ? s_arg : s_str;
146 std::size_t n_total_op_assign = 0;
147 std::size_t n_total_op_assign2 = 0;
148 std::size_t n_total_op_copy = 0;
149 std::size_t n_total_op_move = 0;
153 n_total_op_assign = rg_calls[UTMemFun::assign];
154 n_total_op_assign2 = rg_calls[UTMemFun::assign2];
155 n_total_op_copy = rg_calls[UTMemFun::copy];
156 n_total_op_move = rg_calls[UTMemFun::move];
165 std::size_t throw_count;
166 for (throw_count = 0; ; ++throw_count) {
168 const char* expected = 0;
171#ifndef _RWSTD_NO_EXCEPTIONS
178 expected = exceptions [3];
200 s_str.swap (arg_str);
204 std::size_t n_op_assign =
205 rg_calls[UTMemFun::assign] - n_total_op_assign;
206 std::size_t n_op_assign2 =
207 rg_calls[UTMemFun::assign2] - n_total_op_assign2;
208 std::size_t n_op_copy =
209 rg_calls[UTMemFun::copy] - n_total_op_copy;
210 std::size_t n_op_move =
211 rg_calls[UTMemFun::move] - n_total_op_move;
214 0 == (n_op_assign | n_op_assign2 | n_op_copy | n_op_move);
217 "line %d. %{$FUNCALL}: complexity: %zu assigns, "
218 "%zu assign2s, %zu copies, %zu moves", __LINE__,
219 n_op_assign, n_op_assign2, n_op_copy, n_op_move);
222 if (0 == tcase.
str) {
225 "line %d. %{$FUNCALL}: expected 0 capacity, "
226 "got %zu", __LINE__, arg_str.capacity ());
230 const charT*
const res_p1 = s_str.data ();
231 const charT*
const res_p2 =
232 tcase.
arg ? s_arg.data () : s_str.data ();
234 const std::size_t res1_len = s_str.size ();
235 const std::size_t res2_len =
236 tcase.
arg ? s_arg.size () : s_str.size ();
239 "line %d. %{$FUNCALL}: got offset %td from "
240 "expected value, arg.data (): got offset %td "
241 "from expected value",
242 __LINE__,
p2 - res_p1,
p1 - res_p2);
248 "line %d. %{$FUNCALL}: this == %{#*s}, got this = "
249 "%{/*.*Gs}, differs at pos %zu",
250 __LINE__, int (src_len), src,
int (
sizeof (
charT)),
251 int (res1_len), res_p1, match);
253 match =
rw_match (src, res_p1, res1_len);
256 "line %d. %{$FUNCALL}: str == %{#*s}, got str = "
257 "%{/*.*Gs}, differs at pos %zu",
259 int (
sizeof (
charT)),
int (res2_len),
264#ifndef _RWSTD_NO_EXCEPTIONS
269 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
270 "unexpectedly%{;} caught std::%s(%#s)",
271 __LINE__, 0 != expected, expected,
caught, ex.what ());
276 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
277 "unexpectedly%{;} caught %s",
278 __LINE__, 0 != expected, expected,
caught);
286 std::size_t (-1), std::size_t (-1));
289 std::size_t (-1), std::size_t (-1));
307 else if (0 < tcase.
bthrow) {
309 "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
310 "%{:}unexpectedly caught %s%{;}",
318 const std::size_t expect_throws = 0;
321 "line %d: %{$FUNCALL}: expected exactly 0 %s exception "
322 "while the swap, got %zu",
323 __LINE__, exceptions [3], throw_count);
332template <
class charT>
335 return std::allocator<charT>();
338template <
class charT,
class Types>
346template <
class charT,
class Traits,
class Allocator>
369int main (
int argc,
char** argv)
376 Swap (sig), sig ## _test_cases, \
377 sizeof sig ## _test_cases / sizeof *sig ## _test_cases, \
383 const std::size_t test_count =
sizeof tests /
sizeof *tests;
388 test_swap_func_array, tests, test_count);
std::allocator< charT > make_alloc(SharedAlloc &, std::allocator< charT > *)
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)
_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 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]