41#define At(sig) StringIds::at_ ## sig
42#define OpIndex(sig) StringIds::op_index_ ## sig
44static const char*
const exceptions[] = {
45 "unknown exception",
"out_of_range",
"length_error",
46 "bad_alloc",
"exception"
54op_index_size_test_cases [] = {
57#define TEST(str, off, res) { \
58 __LINE__, off, -1, -1, -1, -1, \
59 str, sizeof str - 1, \
70 TEST (
"<U0>", 0,
'\0'),
72 TEST (
"abc", 0,
'a' ),
73 TEST (
"abc", 1,
'b' ),
74 TEST (
"abc", 2,
'c' ),
76 TEST (
"<U0>ab<U0><U0>c", 0,
'\0'),
78 TEST (
"a<U0>b<U0><U0>c", 0,
'a' ),
79 TEST (
"a<U0>b<U0><U0>c", 1,
'\0'),
80 TEST (
"a<U0>b<U0><U0>c", 2,
'b' ),
81 TEST (
"a<U0>b<U0><U0>c", 3,
'\0'),
82 TEST (
"a<U0>b<U0><U0>c", 4,
'\0'),
83 TEST (
"a<U0>b<U0><U0>c", 5,
'c' ),
85 TEST (
"a<U0>bc<U0><U0>", 5,
'\0'),
87 TEST (
"x@4096", 0,
'x' ),
88 TEST (
"x@4096", 2048,
'x' ),
89 TEST (
"x@4096", 4095,
'x' ),
91 TEST (
"last", 3,
't' )
99op_index_const_size_test_cases [] = {
102#define TEST(str, off, res) { \
103 __LINE__, off, -1, -1, -1, -1, \
104 str, sizeof str - 1, \
118 TEST (
"<U0>", 0,
'\0'),
121 TEST (
"abc", 0,
'a' ),
122 TEST (
"abc", 1,
'b' ),
123 TEST (
"abc", 2,
'c' ),
126 TEST (
"<U0>ab<U0><U0>c", 0,
'\0'),
128 TEST (
"a<U0>b<U0><U0>c", 0,
'a' ),
129 TEST (
"a<U0>b<U0><U0>c", 1,
'\0'),
130 TEST (
"a<U0>b<U0><U0>c", 2,
'b' ),
131 TEST (
"a<U0>b<U0><U0>c", 3,
'\0'),
132 TEST (
"a<U0>b<U0><U0>c", 4,
'\0'),
133 TEST (
"a<U0>b<U0><U0>c", 5,
'c' ),
136 TEST (
"a<U0>bc<U0><U0>", 5,
'\0'),
138 TEST (
"x@4096", 0,
'x' ),
139 TEST (
"x@4096", 2048,
'x' ),
140 TEST (
"x@4096", 4095,
'x' ),
143 TEST (
"last", 3,
't' )
152at_size_test_cases [] = {
154#define at_const_size_test_cases at_size_test_cases
157#define TEST(str, off, res, bthrow) { \
158 __LINE__, off, -1, -1, -1, -1, \
159 str, sizeof str - 1, \
160 0, 0, 0, res, bthrow \
171 TEST (
"a", 0,
'a', 0),
176 TEST (
"<U0>", 0,
'\0', 0),
179 TEST (
"abc", 0,
'a', 0),
180 TEST (
"abc", 1,
'b', 0),
181 TEST (
"abc", 2,
'c', 0),
184 TEST (
"<U0>ab<U0><U0>c", 0,
'\0', 0),
186 TEST (
"a<U0>b<U0><U0>c", 0,
'a', 0),
187 TEST (
"a<U0>b<U0><U0>c", 1,
'\0', 0),
188 TEST (
"a<U0>b<U0><U0>c", 2,
'b', 0),
189 TEST (
"a<U0>b<U0><U0>c", 3,
'\0', 0),
190 TEST (
"a<U0>b<U0><U0>c", 4,
'\0', 0),
191 TEST (
"a<U0>b<U0><U0>c", 5,
'c', 0),
192 TEST (
"a<U0>b<U0><U0>c", 6,
NPOS, 1),
194 TEST (
"a<U0>bc<U0><U0>", 5,
'\0', 0),
196 TEST (
"x@4096", 0,
'x', 0),
197 TEST (
"x@4096", 2048,
'x', 0),
198 TEST (
"x@4096", 4095,
'x', 0),
201 TEST (
"last", 3,
't', 0)
206template <
class charT,
class Traits,
class Allocator>
211 typedef std::basic_string <charT, Traits, Allocator>
String;
212 typedef typename String::size_type SizeT;
214 static const std::size_t BUFSIZE = 256;
216 static charT wstr_buf [BUFSIZE];
217 std::size_t str_len =
sizeof wstr_buf /
sizeof *wstr_buf;
224 if (wstr != wstr_buf)
234#ifndef _RWSTD_NO_EXCEPTIONS
237 const char* expected = 1 == tcase.
bthrow ? exceptions[1] : 0;
244 const charT *pres = 0;
246 switch (
func.which_) {
249 pres = &
str [SizeT (tcase.
off)];
253 pres = &const_str [SizeT (tcase.
off)];
257 pres = &
str.at (SizeT (tcase.
off));
260 case At (const_size):
261 pres = &const_str.at (SizeT (tcase.
off));
265 RW_ASSERT (!
"test logic error: unknown access overload");
269 const char exp_res [2] = {
274 const bool success = 1 ==
rw_match (exp_res, pres, 1);
276 "line %d. %{$FUNCALL} == %{#c}, got %{#c}",
277 __LINE__, tcase.
nres, *pres);
280#ifndef _RWSTD_NO_EXCEPTIONS
282 catch (
const std::out_of_range &ex) {
285 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
286 "unexpectedly%{;} caught std::%s(%#s)",
287 __LINE__, 0 != expected, expected,
caught, ex.what ());
292 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
293 "unexpectedly%{;} caught std::%s(%#s)",
294 __LINE__, 0 != expected, expected,
caught, ex.what ());
299 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
300 "unexpectedly%{;} caught %s",
301 __LINE__, 0 != expected, expected,
caught);
318int main (
int argc,
char** argv)
325 StringIds::sig, sig ## _test_cases, \
326 sizeof sig ## _test_cases / sizeof *sig ## _test_cases \
329 TEST (op_index_size),
330 TEST (op_index_const_size),
335 const std::size_t test_count =
sizeof tests /
sizeof *tests;
void test_access(charT, Traits *, Allocator *, const StringFunc &func, const StringTestCase &tcase)
#define TEST(str, off, res)
std::char_traits< S > Traits
_TEST_EXPORT char * rw_expand(char *, const char *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX, _RWSTD_SIZE_T *=0)
_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 *,...)
StringState rw_get_string_state(const String &str)
#define DEFINE_STRING_TEST_DISPATCH(fname)
_TEST_EXPORT int rw_run_string_test(int, char **, const char *, const char *, StringTestFunc *, const StringTest *, _RWSTD_SIZE_T)
int assert_equal(const StringState &, int, int, const char *) const