42#define Replace(sig) StringIds::replace_ ## sig
44static const char*
const exceptions[] = {
45 "unknown exception",
"out_of_range",
"length_error",
46 "bad_alloc",
"exception"
55iter_iter_cptr_test_cases [] = {
58#define size_size_cptr_test_cases iter_iter_cptr_test_cases
61#define TEST(str, off, size, arg, res, bthrow) { \
62 __LINE__, off, size, -1, -1, -1, \
63 str, sizeof str - 1, \
64 arg, sizeof arg - 1, res, sizeof res - 1, bthrow \
81 TEST (
"ab", 0, 0,
"c",
"cab", 0),
83 TEST (
"", 0, 0,
"",
"", 0),
84 TEST (
"", 0, 0,
"abc",
"abc", 0),
86 TEST (
"ab", 0, 2,
"",
"", 0),
87 TEST (
"ab", 0, 1,
"",
"b", 0),
89 TEST (
"<U0>", 0, 1,
"",
"", 0),
90 TEST (
"<U0>", 0, 1,
"a",
"a", 0),
91 TEST (
"<U0>", 0, 1,
"<U0>@2",
"", 0),
93 TEST (
"ah", 0, 1,
"bcdefg",
"bcdefgh", 0),
94 TEST (
"ah", 1, 1,
"bcdefg",
"abcdefg", 0),
95 TEST (
"ah", 0, 2,
"bcdefg",
"bcdefg", 0),
97 TEST (
"abc", 0, 2,
"cc",
"ccc", 0),
98 TEST (
"abc", 1, 2,
"cc",
"acc", 0),
100 TEST (
"abc", 0, 3,
"defgh",
"defgh", 0),
101 TEST (
"abc", 2, 1,
"defgh",
"abdefgh", 0),
102 TEST (
"abc", 2, 1,
"de<U0>gh",
"abde", 0),
103 TEST (
"abc", 2, 1,
"",
"ab", 0),
104 TEST (
"abc", 1, 1,
"defgh",
"adefghc", 0),
106 TEST (
"abc", 0, 0,
"ee",
"eeabc", 0),
107 TEST (
"abc", 0, 0,
"<U0>@2e<U0>",
"abc", 0),
108 TEST (
"abc", 2, 0,
"ee",
"abeec", 0),
109 TEST (
"abc", 1, 0,
"ee",
"aeebc", 0),
110 TEST (
"abc", 1, 0,
"e<U0>@2",
"aebc", 0),
112 TEST (
"a<U0>b<U0>@2c", 0, 3,
"",
"<U0>@2c", 0),
113 TEST (
"a<U0>b<U0>@2c", 0, 3,
"<U0>e",
"<U0>@2c", 0),
115 TEST (
"<U0>ab<U0>@2c", 0, 0,
"e<U0>",
"e<U0>ab<U0>@2c", 0),
116 TEST (
"a<U0>b<U0>c<U0>", 6, 0,
"e<U0>",
"a<U0>b<U0>c<U0>e", 0),
117 TEST (
"<U0>ab<U0>@2c", 5, 0,
"e<U0>",
"<U0>ab<U0>@2ec", 0),
119 TEST (
"x@4096", 0, 4095,
"ab",
"abx", 0),
120 TEST (
"<U0>@4096", 1, 4094,
"abc",
"<U0>abc<U0>", 0),
121 TEST (
"x@4096", 1, 4094,
"ab",
"xabx", 0),
122 TEST (
"x@4096", 0, 4094,
"ab",
"abxx", 0),
123 TEST (
"x@4096", 1, 4093,
"",
"xxx", 0),
125 TEST (
"x@20", 1, 10,
"x@118",
"x@128", 0),
126 TEST (
"x@128", 128, 0,
"x@79",
"x@207", 0),
127 TEST (
"x@207", 0, 0,
"x@127",
"x@334", 0),
128 TEST (
"x@334", 1, 1,
"x@207",
"x@540", 0),
129 TEST (
"x@540", 0, 539,
"x@334",
"x@335", 0),
130 TEST (
"x@539", 539, 0,
"x@873",
"x@1412", 0),
131 TEST (
"x@3695", 0, 2283,
"",
"x@1412", 0),
132 TEST (
"x@1412", 207, 1,
"x@2284",
"x@3695", 0),
133 TEST (
"x@207", 0, 207,
"x@2284",
"x@2284", 0),
135 TEST (
"", 0, 0,
"x@4096",
"x@4096", 0),
136 TEST (
"a", 0, 1,
"x@4096",
"x@4096", 0),
137 TEST (
"x@4096", 0, 4095,
"x@4096",
"x@4097", 0),
138 TEST (
"<U0>ab<U0>@2c", 0, 6,
"x@4096",
"x@4096", 0),
140 TEST (
"<U0>", 2, 0,
"",
"<U0>", 1),
141 TEST (
"a", 10, 0,
"",
"a", 1),
142 TEST (
"x@4096", 4106, 0,
"",
"x@4096", 1),
144 TEST (
"", 0, 0,
"x@4096",
"x@4096", 0),
147 TEST (
"", 0, 0, 0,
"", 0),
148 TEST (
"abc", 0, 3, 0,
"abc", 0),
149 TEST (
"abc", 1, 1, 0,
"aabcc", 0),
150 TEST (
"a<U0>b<U0>c<U0>", 2, 3, 0,
"a<U0>a<U0>", 0),
151 TEST (
"a<U0>b<U0>c<U0>", 0, 0, 0,
"aa<U0>b<U0>c<U0>", 0),
152 TEST (
"a<U0>b<U0>c<U0>", 6, 0, 0,
"a<U0>b<U0>c<U0>a", 0),
153 TEST (
"<U0>ab<U0>c<U0>", 3, 3, 0,
"<U0>ab", 0),
154 TEST (
"x@4096", 0, 4095, 0,
"x@4097", 0),
156 TEST (
"last", 4, 0,
"test",
"lasttest", 0)
165iter_iter_cstr_test_cases [] = {
168#define size_size_cstr_test_cases iter_iter_cstr_test_cases
171#define TEST(s, off, size, arg, res, bthrow) { \
172 __LINE__, off, size, -1, -1, -1, \
174 arg, sizeof arg - 1, res, sizeof res - 1, bthrow \
191 TEST (
"ab", 0, 0,
"c",
"cab", 0),
193 TEST (
"", 0, 0,
"",
"", 0),
194 TEST (
"", 0, 0,
"<U0>",
"<U0>", 0),
195 TEST (
"", 0, 0,
"abc",
"abc", 0),
197 TEST (
"ab", 0, 2,
"",
"", 0),
198 TEST (
"ab", 0, 1,
"",
"b", 0),
199 TEST (
"ab", 1, 1,
"<U0>",
"a<U0>", 0),
201 TEST (
"<U0>", 0, 1,
"",
"", 0),
202 TEST (
"<U0>", 0, 1,
"a",
"a", 0),
203 TEST (
"<U0>", 0, 1,
"<U0>@2",
"<U0>@2", 0),
205 TEST (
"ah", 0, 1,
"bcdefg",
"bcdefgh", 0),
206 TEST (
"ah", 1, 1,
"bcdefg",
"abcdefg", 0),
207 TEST (
"ah", 0, 2,
"bcdefg",
"bcdefg", 0),
209 TEST (
"abc", 0, 2,
"cc",
"ccc", 0),
210 TEST (
"abc", 1, 2,
"cc",
"acc", 0),
212 TEST (
"abc", 0, 3,
"defgh",
"defgh", 0),
213 TEST (
"abc", 2, 1,
"defgh",
"abdefgh", 0),
214 TEST (
"abc", 2, 1,
"de<U0>gh",
"abde<U0>gh", 0),
215 TEST (
"abc", 2, 1,
"",
"ab", 0),
216 TEST (
"abc", 1, 1,
"defgh",
"adefghc", 0),
218 TEST (
"abc", 0, 0,
"ee",
"eeabc", 0),
219 TEST (
"abc", 0, 0,
"<U0>@2e<U0>",
"<U0>@2e<U0>abc", 0),
220 TEST (
"abc", 2, 0,
"ee",
"abeec", 0),
221 TEST (
"abc", 1, 0,
"ee",
"aeebc", 0),
222 TEST (
"abc", 1, 0,
"e<U0>@2",
"ae<U0>@2bc", 0),
224 TEST (
"a<U0>b<U0>@2c", 0, 3,
"",
"<U0>@2c", 0),
225 TEST (
"a<U0>b<U0>@2c", 0, 3,
"<U0>e",
"<U0>e<U0>@2c", 0),
227 TEST (
"a<U0>b<U0>@2c", 2, 3,
"<U0>e",
"a<U0>@2ec", 0),
228 TEST (
"a<U0>b<U0>@2c", 0, 3,
"<U0>@2e<U0>",
"<U0>@2e<U0>@3c", 0),
229 TEST (
"<U0>ab<U0>@2c", 1, 2,
"<U0>e<U0>@2",
"<U0>@2e<U0>@4c", 0),
231 TEST (
"<U0>ab<U0>@2c", 0, 0,
"<U0>e",
"<U0>e<U0>ab<U0>@2c", 0),
232 TEST (
"a<U0>b<U0>c<U0>", 6, 0,
"e<U0>",
"a<U0>b<U0>c<U0>e<U0>", 0),
233 TEST (
"<U0>ab<U0>@2c", 5, 0,
"<U0>e",
"<U0>ab<U0>@3ec", 0),
235 TEST (
"x@4096", 0, 4095,
"ab",
"abx", 0),
236 TEST (
"x@4096", 1, 4094,
"ab",
"xabx", 0),
237 TEST (
"x@4096", 0, 4094,
"ab",
"abxx", 0),
238 TEST (
"x@4096", 1, 4093,
"",
"xxx", 0),
239 TEST (
"x@4096", 1, 4092,
"<U0>@2",
"x<U0>@2xxx", 0),
241 TEST (
"x@20", 1, 10,
"x@118",
"x@128", 0),
242 TEST (
"x@128", 128, 0,
"x@79",
"x@207", 0),
243 TEST (
"x@207", 0, 0,
"x@127",
"x@334", 0),
244 TEST (
"x@334", 1, 1,
"x@207",
"x@540", 0),
245 TEST (
"x@540", 0, 539,
"x@334",
"x@335", 0),
246 TEST (
"x@539", 539, 0,
"x@873",
"x@1412", 0),
247 TEST (
"x@3695", 0, 2283,
"",
"x@1412", 0),
248 TEST (
"x@1412", 207, 1,
"x@2284",
"x@3695", 0),
249 TEST (
"x@207", 0, 207,
"x@2284",
"x@2284", 0),
251 TEST (
"", 0, 0,
"x@4096",
"x@4096", 0),
252 TEST (
"a", 0, 1,
"x@4096",
"x@4096", 0),
253 TEST (
"x@4096", 0, 4095,
"x@4096",
"x@4097", 0),
254 TEST (
"<U0>ab<U0>@2c", 0, 6,
"x@4096",
"x@4096", 0),
256 TEST (
"<U0>", 2, 0,
"",
"<U0>", 1),
257 TEST (
"a", 10, 0,
"",
"a", 1),
258 TEST (
"x@4096", 4106, 0,
"",
"x@4096", 1),
259 TEST (
"", 0, 0,
"x@4096",
"x@4096", 0),
262 TEST (
"abc", 0, 3, 0,
"abc", 0),
263 TEST (
"abc", 1, 1, 0,
"aabcc", 0),
264 TEST (
"a<U0>b<U0>c<U0>", 2, 3, 0,
"a<U0>a<U0>b<U0>c<U0>@2", 0),
265 TEST (
"a<U0>b<U0>c<U0>", 0, 0, 0,
"a<U0>b<U0>c<U0>a<U0>b<U0>c<U0>", 0),
266 TEST (
"a<U0>b<U0>c<U0>", 6, 0, 0,
"a<U0>b<U0>c<U0>a<U0>b<U0>c<U0>", 0),
267 TEST (
"<U0>ab<U0>c<U0>", 3, 3, 0,
"<U0>ab<U0>ab<U0>c<U0>", 0),
268 TEST (
"x@4096", 0, 4095, 0,
"x@4097", 0),
270 TEST (
"last", 4, 0,
"test",
"lasttest", 0)
279iter_iter_cptr_size_test_cases [] = {
282#define size_size_cptr_size_test_cases iter_iter_cptr_size_test_cases
285#define TEST(str, off, size, arg, count, res, bthrow) { \
286 __LINE__, off, size, -1, count, -1, \
287 str, sizeof str - 1, \
288 arg, sizeof arg - 1, res, sizeof res - 1, bthrow \
306 TEST (
"ab", 0, 0,
"c", 1,
"cab", 0),
308 TEST (
"", 0, 0,
"", 0,
"", 0),
309 TEST (
"", 0, 0,
"abc", 3,
"abc", 0),
311 TEST (
"ab", 0, 2,
"", 0,
"", 0),
312 TEST (
"ab", 0, 1,
"", 0,
"b", 0),
314 TEST (
"<U0>", 0, 1,
"", 0,
"", 0),
315 TEST (
"<U0>", 0, 1,
"a", 1,
"a", 0),
316 TEST (
"<U0>", 0, 1,
"<U0>@2", 2,
"<U0>@2", 0),
318 TEST (
"ah", 0, 1,
"bcdefg", 3,
"bcdh", 0),
319 TEST (
"ah", 1, 1,
"bcdefg", 3,
"abcd", 0),
320 TEST (
"ah", 0, 2,
"bcdefg", 5,
"bcdef", 0),
322 TEST (
"abc", 0, 2,
"cc", 2,
"ccc", 0),
323 TEST (
"abc", 1, 2,
"cc", 2,
"acc", 0),
324 TEST (
"abc", 2, 1,
"defgh", 1,
"abd", 0),
325 TEST (
"abc", 2, 1,
"de<U0>gh", 3,
"abde<U0>", 0),
326 TEST (
"abc", 2, 1,
"", 0,
"ab", 0),
328 TEST (
"abc", 0, 0,
"ee", 2,
"eeabc", 0),
329 TEST (
"abc", 0, 0,
"<U0>@2e<U0>", 4,
"<U0>@2e<U0>abc",0),
330 TEST (
"abc", 2, 0,
"ee", 2,
"abeec", 0),
331 TEST (
"abc", 1, 0,
"ee", 1,
"aebc", 0),
333 TEST (
"a<U0>b<U0>@2c", 0, 3,
"", 0,
"<U0>@2c", 0),
334 TEST (
"a<U0>b<U0>@2c", 0, 3,
"e<U0>", 2,
"e<U0>@3c", 0),
335 TEST (
"a<U0>b<U0>@2c", 2, 3,
"e<U0>", 1,
"a<U0>ec", 0),
336 TEST (
"a<U0>b<U0>@2c", 2, 3,
"<U0>e", 2,
"a<U0>@2ec", 0),
337 TEST (
"<U0>ab<U0>@2c", 2, 3,
"<U0>e", 2,
"<U0>a<U0>ec", 0),
338 TEST (
"a<U0>b<U0>@2c", 0, 6,
"e<U0>", 2,
"e<U0>", 0),
340 TEST (
"x@4096", 1, 4095,
"<U0>", 1,
"x<U0>", 0),
341 TEST (
"x@4096", 0, 4095,
"ab", 2,
"abx", 0),
342 TEST (
"x@4096", 1, 4094,
"ab", 1,
"xax", 0),
343 TEST (
"x@4096", 0, 4094,
"ab", 2,
"abxx", 0),
344 TEST (
"x@4096", 1, 4093,
"", 0,
"xxx", 0),
345 TEST (
"x@4096", 1, 4092,
"<U0>@2", 2,
"x<U0>@2xxx", 0),
347 TEST (
"", 0, 0,
"x@873", 540,
"x@540", 0),
348 TEST (
"x@20", 1, 10,
"x@118", 118,
"x@128", 0),
349 TEST (
"x@128", 128, 0,
"x@79", 79,
"x@207", 0),
350 TEST (
"x@207", 0, 0,
"x@127", 127,
"x@334", 0),
351 TEST (
"x@207", 207, 207,
"x@207", 127,
"x@334", 0),
352 TEST (
"x@334", 0, 207,
"x@545", 540,
"x@667", 0),
353 TEST (
"x@539", 0, 539,
"x@873", 873,
"x@873", 0),
354 TEST (
"x@878", 5, 5,
"x@540", 539,
"x@1412", 0),
355 TEST (
"x@872", 0, 0,
"x@1412", 1412,
"x@2284", 0),
356 TEST (
"x@1411", 1411, 0,
"x@2284", 2284,
"x@3695", 0),
357 TEST (
"x@1411", 873, 538,
"x@3695", 2822,
"x@3695", 0),
358 TEST (
"x@1412", 0, 0,
"x@2284", 2284,
"x@3696", 0),
359 TEST (
"", 0, 0,
"x@3696", 3696,
"x@3696", 0),
361 TEST (
"a", 0, 1,
"x@4096", 4095,
"x@4095", 0),
362 TEST (
"x@4096", 0, 4095,
"y@4096", 4095,
"y@4095x", 0),
363 TEST (
"x@4096", 0, 2047,
"x@4096", 2047,
"x@4096", 0),
365 TEST (
"x@4096", 2047, 2048,
"x@4096", 2048,
"x@4096", 0),
367 TEST (
"<U0>", 2, 0,
"", 0,
"<U0>", 1),
368 TEST (
"a", 10, 0,
"", 0,
"a", 1),
369 TEST (
"x@4096", 4106, 0,
"", 0,
"x@4096", 1),
371 TEST (
"a", 0, 1,
"x@4096", 4095,
"x@4095", 0),
374 TEST (
"a", 0, 0, 0 , 1,
"aa", 0),
375 TEST (
"a", 0, 1, 0 , 1,
"a", 0),
376 TEST (
"a", 1, 0, 0 , 1,
"aa", 0),
377 TEST (
"abc", 0, 3, 0 , 2,
"ab", 0),
378 TEST (
"abc", 1, 1, 0 , 3,
"aabcc", 0),
379 TEST (
"a<U0>b<U0>c<U0>", 2, 3, 0, 6,
"a<U0>a<U0>b<U0>c<U0>@2", 0),
380 TEST (
"a<U0>b<U0>c<U0>", 0, 0, 0, 4,
"a<U0>b<U0>a<U0>b<U0>c<U0>", 0),
381 TEST (
"<U0>ab<U0>c<U0>", 6, 0, 0 , 1,
"<U0>ab<U0>c<U0>@2", 0),
382 TEST (
"<U0>ab<U0>c<U0>", 3, 3, 0 , 2,
"<U0>ab<U0>a", 0),
383 TEST (
"a@4096", 0, 1, 0 , 1111,
"a@5206", 0),
384 TEST (
"b@4096", 1, 2, 0 , 2222,
"b@6316", 0),
385 TEST (
"x@4096", 0, 4095, 0 , 4095,
"x@4096", 0),
386 TEST (
"x@4096", 0, 4095, 0 , 1,
"xx", 0),
388 TEST (
"last", 4, 0,
"test", 4,
"lasttest", 0)
397iter_iter_range_test_cases [] = {
400#define size_size_cstr_size_size_test_cases iter_iter_range_test_cases
403#define TEST(str, off, size, arg, off2, size2, res, bthrow) { \
404 __LINE__, off, size, off2, size2, -1, \
405 str, sizeof str - 1, \
406 arg, sizeof arg - 1, res, sizeof res - 1, bthrow \
425 TEST (
"", 0, 0,
"", 0, 0,
"", 0),
426 TEST (
"", 0, 0,
"", 0, -1,
"", 0),
427 TEST (
"", 0, 0,
"", 0, 1,
"", 0),
429 TEST (
"", 0, 1,
"", 0, 0,
"", 0),
430 TEST (
"", 0, 1,
"", 0, 1,
"", 0),
431 TEST (
"", 0, 1,
"", 0, -1,
"", 0),
433 TEST (
"", 0, -1,
"", 0, 0,
"", 0),
434 TEST (
"", 0, -1,
"", 0, 1,
"", 0),
435 TEST (
"", 0, -1,
"", 0, -1,
"", 0),
437 TEST (
"1", 0, 0,
"", 0, 0,
"1", 0),
438 TEST (
"2", 0, 0,
"", 0, -1,
"2", 0),
439 TEST (
"3", 0, 0,
"", 0, 1,
"3", 0),
441 TEST (
"4", 0, 1,
"", 0, 0,
"", 0),
442 TEST (
"5", 0, 1,
"", 0, 1,
"", 0),
443 TEST (
"6", 0, 1,
"", 0, -1,
"", 0),
445 TEST (
"7", 0, -1,
"", 0, 0,
"", 0),
446 TEST (
"8", 0, -1,
"", 0, 1,
"", 0),
447 TEST (
"9", 0, -1,
"", 0, -1,
"", 0),
449 TEST (
"1", 0, 0,
"9", 0, 0,
"1", 0),
450 TEST (
"2", 0, 0,
"8", 0, -1,
"82", 0),
451 TEST (
"3", 0, 0,
"7", 0, 1,
"73", 0),
453 TEST (
"4", 0, 1,
"6", 0, 0,
"", 0),
454 TEST (
"5", 0, 1,
"5", 0, 1,
"5", 0),
455 TEST (
"6", 0, 1,
"4", 0, -1,
"4", 0),
457 TEST (
"7", 0, -1,
"3", 0, 0,
"", 0),
458 TEST (
"8", 0, -1,
"2", 0, 1,
"2", 0),
459 TEST (
"9", 0, -1,
"1", 0, -1,
"1", 0),
461 TEST (
"", 0, 0,
"abc", 0, 3,
"abc", 0),
463 TEST (
"ab", 0, 0,
"c", 0, 1,
"cab", 0),
464 TEST (
"ab", 0, 2,
"", 0, 0,
"", 0),
465 TEST (
"ab", 0, 1,
"", 0, 0,
"b", 0),
467 TEST (
"<U0>", 0, 1,
"", 0, 0,
"", 0),
468 TEST (
"<U0>", 0, 1,
"a", 0, 1,
"a", 0),
469 TEST (
"<U0>", 0, 1,
"<U0>@2", 1, 1,
"<U0>", 0),
470 TEST (
"<U0>", 0, 1,
"<U0>@2", 0, 2,
"<U0>@2", 0),
472 TEST (
"ah", 0, 1,
"bcdefg", 0, 3,
"bcdh", 0),
473 TEST (
"ah", 1, 1,
"bcdefg", 0, 3,
"abcd", 0),
474 TEST (
"ah", 0, 1,
"bcdefg", 1, 3,
"cdeh", 0),
475 TEST (
"ah", 1, 1,
"bcdefg", 1, 3,
"acde", 0),
476 TEST (
"ah", 0, 1,
"bcdefg", 0, 6,
"bcdefgh", 0),
477 TEST (
"ah", 1, 1,
"bcdefg", 0, 6,
"abcdefg", 0),
479 TEST (
"abc", 0, 2,
"cc", 0, 2,
"ccc", 0),
480 TEST (
"abc", 1, 2,
"cc", 0, 2,
"acc", 0),
482 TEST (
"abc", 0, 3,
"d", 0, 1,
"d", 0),
483 TEST (
"abc", 0, 3,
"def", 0, 3,
"def", 0),
484 TEST (
"abc", 0, 3,
"defgh", 0, 5,
"defgh", 0),
485 TEST (
"abc", 2, 1,
"defgh", 4, 1,
"abh", 0),
486 TEST (
"abc", 2, 1,
"de<U0>gh", 2, 1,
"ab<U0>", 0),
487 TEST (
"abc", 2, 1,
"", 0, 0,
"ab", 0),
489 TEST (
"abc", 1, 1,
"defgh", 1, 2,
"aefc", 0),
490 TEST (
"abc", 0, 0,
"ee", 0, 2,
"eeabc", 0),
491 TEST (
"abc", 0, 0,
"<U0>@2e<U0>", 0, 4,
"<U0>@2e<U0>abc",0),
492 TEST (
"abc", 2, 0,
"ee", 0, 2,
"abeec", 0),
493 TEST (
"abc", 2, 1,
"<U0>e<U0>@2", 0, 4,
"ab<U0>e<U0>@2", 0),
494 TEST (
"abc", 1, 0,
"ee", 0, 2,
"aeebc", 0),
495 TEST (
"abc", 1, 0,
"<U0>e<U0>@2", 0, 4,
"a<U0>e<U0>@2bc", 0),
497 TEST (
"a<U0>b<U0>@2c", 0, 3,
"", 0, 0,
"<U0>@2c", 0),
498 TEST (
"<U0>ab<U0>@2c", 0, 3,
"", 0, 0,
"<U0>@2c", 0),
499 TEST (
"a<U0>b<U0>@2c", 0, 3,
"<U0>e", 0, 2,
"<U0>e<U0>@2c", 0),
501 TEST (
"a<U0>b<U0>@2c", 2, 3,
"<U0>e", 0, 2,
"a<U0>@2ec", 0),
502 TEST (
"a<U0>b<U0>@2c", 2, 3,
"<U0>e", 1, 1,
"a<U0>ec", 0),
503 TEST (
"<U0>ab<U0>@2c", 2, 3,
"<U0>e", 0, 2,
"<U0>a<U0>ec", 0),
504 TEST (
"<U0>ab<U0>@2c", 2, 3,
"<U0>e<U0>@2", 1, 3,
"<U0>ae<U0>@2c", 0),
506 TEST (
"a<U0>b<U0>@2c", 0, 6,
"<U0>e", 0, 2,
"<U0>e", 0),
507 TEST (
"a<U0>b<U0>@2c", 0, 6,
"<U0>e", 0, 1,
"<U0>", 0),
509 TEST (
"<U0>ab<U0>@2c", 0, 0,
"<U0>e", 0, 2,
"<U0>e<U0>ab<U0>@2c", 0),
510 TEST (
"a<U0>b<U0>c<U0>", 6, 0,
"e<U0>", 0, 2,
"a<U0>b<U0>c<U0>e<U0>", 0),
511 TEST (
"<U0>ab<U0>@2c", 5, 0,
"<U0>e", 0, 2,
"<U0>ab<U0>@3ec", 0),
515 TEST (
"a", 0, 0,
"b", 0, -1,
"ba", 0),
516 TEST (
"a@0", 0, 0,
"b@0", 0, -1,
"", 0),
517 TEST (
"a@0", 0, 0,
"b@1", 0, -1,
"b", 0),
518 TEST (
"a@1", 0, 0,
"b@0", 0, -1,
"a", 0),
519 TEST (
"a@1", 0, 0,
"b@1", 0, -1,
"ba", 0),
520 TEST (
"a@2", 0, 0,
"b@2", 0, -1,
"bbaa", 0),
522 TEST (
"a@1000", 0, 0,
"b@1000", 0, -1,
"b@1000a@1000", 0),
523 TEST (
"a@1000", 0, 1,
"b@1001", 0, -1,
"b@1001a@999", 0),
524 TEST (
"a@1000", 0, 2,
"b@1002", 0, -1,
"b@1002a@998", 0),
525 TEST (
"a@1000", 1, 998,
"b@1003", 0, -1,
"ab@1003a", 0),
526 TEST (
"a@1000", 2, 996,
"b@1004", 0, -1,
"aab@1004aa", 0),
527 TEST (
"a@1000", 500, 250,
"b@1005", 0, -1,
"a@500b@1005a@250", 0),
528 TEST (
"a@1000", 998, 1,
"b@1006", 0, -1,
"a@998b@1006a", 0),
529 TEST (
"a@2000", 1000, -1,
"b", 0, -1,
"a@1000b", 0),
530 TEST (
"a@2000", 1000, 999,
"bb", 0, -1,
"a@1000bba", 0),
532 TEST (
"x@4096", 0, 4095,
"ab", 0, 2,
"abx", 0),
533 TEST (
"x@4096", 1, 4094,
"ab", 0, 2,
"xabx", 0),
534 TEST (
"x@4096", 0, 4094,
"ab", 0, 2,
"abxx", 0),
535 TEST (
"x@4096", 1, 4093,
"", 0, 0,
"xxx", 0),
536 TEST (
"x@4096", 1, 4092,
"<U0>@2", 0, 2,
"x<U0>@2xxx", 0),
538 TEST (
"a", 0, 1,
"x@4096", 0, 4095,
"x@4095", 0),
539 TEST (
"x@4096", 0, 4095,
"x@4096", 0, 4095,
"x@4096", 0),
540 TEST (
"x@4096", 0, 2047,
"x@4096", 0, 2047,
"x@4096", 0),
542 TEST (
"", 0, 0,
"x@334", 0, 207,
"x@207", 0),
543 TEST (
"x@20", 1, 10,
"x@118", 0, 118,
"x@128", 0),
544 TEST (
"x@128", 0, 0,
"x@129", 50, 79,
"x@207", 0),
545 TEST (
"x@207", 207, 0,
"x@127", 0, 127,
"x@334", 0),
546 TEST (
"x@208", 128, 1,
"x@207", 10, 127,
"x@334", 0),
547 TEST (
"x@335", 334, 1,
"x@208", 2, 206,
"x@540", 0),
548 TEST (
"x@540", 0, 0,
"x@336", 3, 333,
"x@873", 0),
549 TEST (
"x@334", 0, 334,
"x@873", 0, 873,
"x@873", 0),
550 TEST (
"x@873", 0, 873,
"x@541", 1, 540,
"x@540", 0),
551 TEST (
"x@872", 0, 0,
"x@1412", 0, 1412,
"x@2284", 0),
552 TEST (
"x@1411", 1411, 0,
"x@2288", 4, 2284,
"x@3695", 0),
553 TEST (
"x@873", 540,333,
"x@3695",3695, 0,
"x@540", 0),
554 TEST (
"x@1412", 0, 1412,
"x@3696", 0,3695,
"x@3695", 0),
556 TEST (
"x@4096", 2047, 2048,
"x@4096", 0, 2048,
"x@4096", 0),
558 TEST (
"<U0>", 2, 0,
"", 0, 0,
"<U0>", 1),
559 TEST (
"<U0>", 0, 0,
"<U0>", 2, 0,
"<U0>", 2),
561 TEST (
"a", 10, 0,
"", 0, 0,
"a", 1),
562 TEST (
"a", 0, 0,
"a", 10, 0,
"a", 2),
564 TEST (
"x@4096", 4106, 0,
"", 0, 0,
"x@4096", 1),
565 TEST (
"x@4096", 0, 0,
"x@4096", 4106, 0,
"x@4096", 2),
567 TEST (
"a", 0, 1,
"x@4096", 0, 4095,
"x@4095", 0),
571 TEST (
"", 0, 0, 0, 0, 0,
"", 0),
572 TEST (
"", 0, 0, 0, 0, 1,
"", 0),
573 TEST (
"", 0, 0, 0, 0, -1,
"", 0),
575 TEST (
"", 0, 1, 0, 0, 0,
"", 0),
576 TEST (
"", 0, 1, 0, 0, 1,
"", 0),
577 TEST (
"", 0, 1, 0, 0, -1,
"", 0),
579 TEST (
"", 0, -1, 0, 0, 0,
"", 0),
580 TEST (
"", 0, -1, 0, 0, 1,
"", 0),
581 TEST (
"", 0, -1, 0, 0, -1,
"", 0),
583 TEST (
"1", 0, 0, 0, 0, 0,
"1", 0),
584 TEST (
"2", 0, 0, 0, 0, -1,
"22", 0),
585 TEST (
"3", 0, 0, 0, 0, 1,
"33", 0),
587 TEST (
"4", 0, 1, 0, 0, 0,
"", 0),
588 TEST (
"5", 0, 1, 0, 0, 1,
"5", 0),
589 TEST (
"6", 0, 1, 0, 0, -1,
"6", 0),
591 TEST (
"7", 0, -1, 0, 0, 0,
"", 0),
592 TEST (
"8", 0, -1, 0, 0, 1,
"8", 0),
593 TEST (
"9", 0, -1, 0, 0, -1,
"9", 0),
595 TEST (
"x@4096", 0, 0, 0, 0, 0,
"x@4096", 0),
596 TEST (
"x@4096", 0, 1, 0, 0, 1,
"x@4096", 0),
597 TEST (
"x@4096", 0, 2, 0, 0, 2,
"x@4096", 0),
598 TEST (
"x@4096", 0, -1, 0, 0, -1,
"x@4096", 0),
600 TEST (
"abc", 0, 0, 0, 1, 1,
"babc", 0),
601 TEST (
"abc", 2, 0, 0, 0, 2,
"ababc", 0),
602 TEST (
"a<U0>bc<U0>@2", 0, 0, 0, 4, 2,
"<U0>@2a<U0>bc<U0>@2", 0),
603 TEST (
"a<U0>bc<U0>@2", 6, 0, 0, 1, 3,
"a<U0>bc<U0>@3bc", 0),
604 TEST (
"abcdef", 0, 0, 0, 1, 2,
"bcabcdef", 0),
606 TEST (
"last", 4, 0,
"test", 0, 4,
"lasttest", 0)
615iter_iter_size_val_test_cases [] = {
618#define size_size_size_val_test_cases iter_iter_size_val_test_cases
621#define TEST(str, off, size, count, val, res, bthrow) { \
622 __LINE__, off, size, -1, count, val, \
623 str, sizeof str - 1, \
624 0, 0, res, sizeof res - 1, bthrow \
642 TEST (
"ab", 0, 0, 1,
'c',
"cab", 0),
644 TEST (
"", 0, 0, 0,
'c',
"", 0),
645 TEST (
"", 0, 0, 3,
'c',
"ccc", 0),
647 TEST (
"ab", 0, 2, 0,
'c',
"", 0),
648 TEST (
"ab", 0, 1, 0,
'c',
"b", 0),
650 TEST (
"<U0>", 0, 1, 0,
' ',
"", 0),
651 TEST (
"<U0>", 0, 1, 1,
'a',
"a", 0),
652 TEST (
"<U0>", 0, 1, 1,
'\0',
"<U0>", 0),
653 TEST (
"<U0>", 0, 1, 2,
'\0',
"<U0>@2", 0),
655 TEST (
"ah", 0, 1, 1,
'c',
"ch", 0),
656 TEST (
"ah", 1, 1, 1,
'c',
"ac", 0),
657 TEST (
"ah", 0, 1, 4,
'c',
"cccch", 0),
658 TEST (
"ah", 1, 1, 4,
'c',
"acccc", 0),
660 TEST (
"abc", 0, 2, 2,
'c',
"ccc", 0),
661 TEST (
"abc", 1, 2, 2,
'c',
"acc", 0),
663 TEST (
"abc", 0, 3, 1,
'c',
"c", 0),
664 TEST (
"abc", 0, 3, 5,
'c',
"ccccc", 0),
665 TEST (
"abc", 2, 1, 1,
'c',
"abc", 0),
666 TEST (
"abc", 2, 1, 0,
'c',
"ab", 0),
668 TEST (
"abc", 1, 1, 5,
'c',
"acccccc", 0),
669 TEST (
"abc", 0, 0, 2,
'c',
"ccabc", 0),
670 TEST (
"abc", 0, 0, 3,
'\0',
"<U0>@3abc", 0),
671 TEST (
"abc", 2, 0, 2,
'e',
"abeec", 0),
672 TEST (
"abc", 2, 0, 3,
'\0',
"ab<U0>@3c", 0),
673 TEST (
"abc", 1, 0, 1,
'\0',
"a<U0>bc", 0),
675 TEST (
"a<U0>b<U0>@2c", 0, 3, 1,
'\0',
"<U0>@3c", 0),
676 TEST (
"a<U0>b<U0>@2c", 2, 3, 2,
'\0',
"a<U0>@3c", 0),
677 TEST (
"a<U0>b<U0>@2c", 2, 2, 1,
'\0',
"a<U0>@3c", 0),
678 TEST (
"<U0>ab<U0>@2c", 2, 3, 0,
'\0',
"<U0>ac", 0),
679 TEST (
"<U0>ab<U0>@2c", 2, 1, 2,
'\0',
"<U0>a<U0>@4c", 0),
681 TEST (
"a<U0>b<U0>@2c", 0, 6, 2,
'\0',
"<U0>@2", 0),
683 TEST (
"<U0>ab<U0>@2c", 0, 0, 2,
'\0',
"<U0>@3ab<U0>@2c", 0),
684 TEST (
"a<U0>b<U0>c<U0>", 6, 0, 2,
'\0',
"a<U0>b<U0>c<U0>@3", 0),
685 TEST (
"<U0>ab<U0>@2c", 5, 0, 1,
'\0',
"<U0>ab<U0>@3c", 0),
687 TEST (
"x@4096", 0, 4095, 2,
'a',
"aax", 0),
688 TEST (
"x@4096", 1, 4094, 2,
'a',
"xaax", 0),
689 TEST (
"x@4096", 0, 4094, 2,
'a',
"aaxx", 0),
690 TEST (
"x@4096", 1, 4093, 0,
'a',
"xxx", 0),
691 TEST (
"x@4096", 1, 4092, 1,
'\0',
"x<U0>xxx", 0),
693 TEST (
"x@127", 0, 0, 1,
'x',
"x@128", 0),
694 TEST (
"x@200", 128, 7, 14,
'x',
"x@207", 0),
695 TEST (
"x@331", 331, 1, 3,
'x',
"x@334", 0),
696 TEST (
"x@539", 539, 0, 1,
'x',
"x@540", 0),
697 TEST (
"x@539", 0, 0,873,
'x',
"x@1412", 0),
698 TEST (
"x@873", 873, 0, 1411,
'x',
"x@2284", 0),
699 TEST (
"x@3694", 128, 1, 2,
'x',
"x@3695", 0),
700 TEST (
"x@539", 537, 2, 3,
'a',
"x@537aaa", 0),
701 TEST (
"", 0, 0, 3695,
'x',
"x@3695", 0),
703 TEST (
"a", 0, 1, 4095,
'x',
"x@4095", 0),
704 TEST (
"x@4096", 0, 4095, 4095,
'a',
"a@4095x", 0),
705 TEST (
"x@4096", 0, 2047, 2047,
'b',
"b@2047x@2049", 0),
707 TEST (
"x@4096", 2047, 2048, 2048,
'x',
"x@4096", 0),
709 TEST (
"<U0>", 2, 0, 0,
' ',
"<U0>", 1),
710 TEST (
"a", 10, 0, 0,
' ',
"a", 1),
711 TEST (
"x@4096", 4106, 0, 0,
' ',
"x@4096", 1),
713 TEST (
"a", 0, 1, 4095,
'x',
"x@4095", 0),
715 TEST (
"last", 4, 0, 4,
't',
"lasttttt", 0)
722template <
class String,
class Iterator>
753 return str.replace (first1, last1, first2, last2);
760template <
class String,
class Iterator>
781 const std::size_t srclen_ = tcase.
arg ? tdata.
arglen_ :
str.size ();
783 const std::size_t
off =
785 const std::size_t ext = tdata.
ext2_;
787 if (0 == tcase.
arg) {
792 const Iterator last2 (first2 + ext);
794 return str.replace (first1, last1, first2, last2);
800 const Iterator last2 (first2 + ext);
802 return str.replace (first1, last1, first2, last2);
808template <
class charT,
class Traits,
class Allocator>
810 std::basic_string <charT, Traits, Allocator> > &rng,
813 typedef std::basic_string <charT, Traits, Allocator>
String;
814 typedef typename String::iterator StringIter;
832 const StringIter first (
str.begin () + tdata.
off1_);
833 const StringIter
last (first + tdata.
ext1_);
836 const std::size_t arg_off = std::size_t (tcase.
off);
837 const std::size_t arg_size = std::size_t (tcase.
size);
838 const std::size_t arg_off2 = std::size_t (tcase.
off2);
839 const std::size_t arg_size2 =
843 const charT*
const arg_ptr = tcase.
arg ?
arg.data () :
str.data ();
850 std::size_t* length_calls =
856 length_calls += TraitsFunc::length;
866 const bool use_iters =
872 std::size_t throw_count;
873 for (throw_count = 0; ; ++throw_count) {
876 const char* expected = 0;
879#ifndef _RWSTD_NO_EXCEPTIONS
881 if (1 == tcase.
bthrow && !use_iters)
882 expected = exceptions [1];
883 else if (2 == tcase.
bthrow && !use_iters)
884 expected = exceptions [1];
885 else if (3 == tcase.
bthrow && !use_iters)
886 expected = exceptions [2];
887 else if (0 == tcase.
bthrow) {
891 expected = exceptions [3];
908 const String* ret_ptr = 0;
914 switch (
func.which_) {
916 ret_ptr = &
str.replace (arg_off, arg_size, arg_ptr);
920 ret_ptr = &
str.replace (arg_off, arg_size, arg_str);
923 case Replace (size_size_cptr_size):
924 ret_ptr = &
str.replace (arg_off, arg_size, arg_ptr, arg_size2);
927 case Replace (size_size_cstr_size_size):
928 ret_ptr = &
str.replace (arg_off, arg_size, arg_str,
929 arg_off2, arg_size2);
932 case Replace (size_size_size_val):
933 ret_ptr = &
str.replace (arg_off, arg_size, arg_size2, arg_val);
937 ret_ptr = &
str.replace (first,
last, arg_ptr);
941 ret_ptr = &
str.replace (first,
last, arg_str);
944 case Replace (iter_iter_cptr_size):
945 ret_ptr = &
str.replace (first,
last, arg_ptr, arg_size2);
948 case Replace (iter_iter_size_val):
949 ret_ptr = &
str.replace (first,
last, arg_size2, arg_val);
952 case Replace (iter_iter_range):
953 ret_ptr = &rng (
str, tdata);
957 RW_ASSERT (!
"logic error: unknown replace overload");
963 const std::ptrdiff_t ret_off = ret_ptr - &
str;
967 "line %d. %{$FUNCALL} returned invalid reference, "
968 "offset is %td", __LINE__, ret_off);
971 static const int cwidth =
sizeof (
charT);
975 "line %d. %{$FUNCALL} expected %{/*.*Gs} with "
976 "length %zu, got %{/*.*Gs} with length %zu",
986 const std::size_t match =
990 "line %d. %{$FUNCALL} expected %{/*.*Gs}, "
991 "got %{/*.*Gs}, difference at offset %zu",
994 cwidth, int (
str.size ()),
str.data (), match);
1000 0, tcase.
line,
"line %d. %{$FUNCALL} doesn't "
1001 "use traits_type::length()", __LINE__);
1005#ifndef _RWSTD_NO_EXCEPTIONS
1007 catch (
const std::out_of_range &ex) {
1010 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
1011 "unexpectedly%{;} caught std::%s(%#s)",
1012 __LINE__, 0 != expected, expected,
caught, ex.what ());
1014 catch (
const std::length_error &ex) {
1017 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
1018 "unexpectedly%{;} caught std::%s(%#s)",
1019 __LINE__, 0 != expected, expected,
caught, ex.what ());
1024 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
1025 "unexpectedly%{;} caught std::%s(%#s)",
1026 __LINE__, 0 != expected, expected,
caught, ex.what ());
1031 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
1032 "unexpectedly%{;} caught std::%s(%#s)",
1033 __LINE__, 0 != expected, expected,
caught, ex.what ());
1038 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
1039 "unexpectedly%{;} caught %s",
1040 __LINE__, 0 != expected, expected,
caught);
1048 std::size_t (-1), std::size_t (-1));
1063 else if (0 < tcase.
bthrow) {
1065 "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
1066 "%{:}unexpectedly caught %s%{;}",
1073#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
1077 const std::size_t expect_throws = str_state.
capacity_ <
str.capacity ();
1090 "line %d: %{$FUNCALL}: expected exactly 1 %s exception "
1091 "while changing capacity from %zu to %zu, got %zu",
1092 __LINE__, exceptions [3],
1096 "line %d: %{$FUNCALL}: expected at least 1 %s exception "
1097 "while changing capacity from %zu to %zu, got %zu",
1098 __LINE__, exceptions [3],
1108template <
class charT,
class Traits,
class Allocator>
1112 typedef std::basic_string<charT, Traits, Allocator>
String;
1121#define TEST(Iterator) do { \
1122 typedef typename String::Iterator Iter; \
1124 ReplaceRangeOverload<String, Iter> rng; \
1125 test_replace ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata); \
1140#define TEST(Iterator) do { \
1141 typedef Iterator<charT> Iter; \
1143 ReplaceRange<String, Iter> rng; \
1144 test_replace ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata); \
1153 rw_error (0, 0, __LINE__,
"bad iterator id");
1173#define TEST(sig) { \
1174 Replace (sig), sig ## _test_cases, \
1175 sizeof sig ## _test_cases / sizeof *sig ## _test_cases, \
1178 TEST (size_size_cptr),
1179 TEST (size_size_cstr),
1180 TEST (size_size_cptr_size),
1181 TEST (size_size_cstr_size_size),
1182 TEST (size_size_size_val),
1183 TEST (iter_iter_cptr),
1184 TEST (iter_iter_cstr),
1185 TEST (iter_iter_cptr_size),
1186 TEST (iter_iter_size_val),
1187 TEST (iter_iter_range)
1190 const std::size_t test_count =
sizeof tests /
sizeof *tests;
1194 "lib.string.replace",
1195 test_replace_func_array, tests, test_count);
#define TEST(str, off, size, arg, res, bthrow)
void test_replace(charT *, Traits *, Allocator *, const RangeBase< std::basic_string< charT, Traits, Allocator > > &rng, 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)
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)
static StringPtr begin(String &str, StringPtr *)
virtual String & operator()(String &str, const StringTestCaseData< StringChar > &tdata) const
String::value_type StringChar
String::iterator StringIter
virtual String & operator()(String &str, const StringTestCaseData< StringChar > &tdata) const
String::value_type StringChar
String::iterator StringIter
static SharedAlloc * instance(SharedAlloc *=0)
_RWSTD_SIZE_T throw_at_calls_[n_funs]
StringIds::OverloadId which_
StringIds::IteratorId iter_id_
static ArgId arg_type(OverloadId id, int argno)
int assert_equal(const StringState &, int, int, const char *) const
_RWSTD_SIZE_T * throw_at_calls_[2]
_RWSTD_SIZE_T new_calls_[2]