41#define Compare(sig) StringIds::compare_ ## 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, 0, res, bthrow \
72 TEST (
"ab",
"ab", 0, 0),
75 TEST (
"",
"\0", 0, 0),
78 TEST (
"\0",
"", 1, 0),
79 TEST (
"\0",
"\0", 1, 0),
82 TEST (
"abcdefghij",
"abcdefghij", 0, 0),
83 TEST (
"abcdefghij",
"abcdefghi", 1, 0),
84 TEST (
"abcdefghi",
"abcdefghij",
NPOS, 0),
86 TEST (
"abbdefghij",
"abcdefghij",
NPOS, 0),
87 TEST (
"abcdeeghij",
"abcdefghij",
NPOS, 0),
88 TEST (
"abcdefghii",
"abcdefghij",
NPOS, 0),
90 TEST (
"bbcdefghij",
"a", 1, 0),
91 TEST (
"eeeeeeghij",
"aeeee", 1, 0),
93 TEST (
"aeeee",
"eeeeeeghij",
NPOS, 0),
95 TEST (
"bbcdefghij",
"abcdefghij", 1, 0),
96 TEST (
"abcdffghij",
"abcdefghij", 1, 0),
97 TEST (
"abcdefghjj",
"abcdefghij", 1, 0),
99 TEST (
"a\0b\0\0c",
"a\0b\0\0c", 1, 0),
100 TEST (
"abc\0\0\0",
"abc\0\0\0", 1, 0),
101 TEST (
"\0ab\0\0c",
"e\0ab\0\0c",
NPOS, 0),
103 TEST (
"a\0b",
"a\0b\0\0c", 1, 0),
104 TEST (
"ab\0",
"abc\0\0\0",
NPOS, 0),
105 TEST (
"\0ab",
"e\0ab\0\0c",
NPOS, 0),
107 TEST (
"x@4096",
"x@4096", 0, 0),
109 TEST (
"x@4096",
"xxxxxx", 1, 0),
111 TEST (
"x@4096",
"a\0b", 1, 0),
113 TEST (
"a@2048b@2048",
"a@2048b@2047", 1, 0),
114 TEST (
"a@2048b@2048",
"a@2048b@2047c",
NPOS, 0),
115 TEST (
"a@2048cb@2047",
"a@2048cb@2047", 0, 0),
117 TEST (
"last",
"last", 0, 0)
125cstr_test_cases [] = {
128#define TEST(str, arg, res, bthrow) { \
129 __LINE__, -1, -1, -1, -1, -1, \
130 str, sizeof str - 1, \
131 arg, sizeof arg - 1, 0, res, bthrow \
144 TEST (
"ab",
"ab", 0, 0),
150 TEST (
"\0",
"", 1, 0),
151 TEST (
"\0",
"\0", 0, 0),
154 TEST (
"abcdefghij",
"abcdefghij", 0, 0),
155 TEST (
"abcdefghij",
"abcdefghi", 1, 0),
156 TEST (
"abcdefghi",
"abcdefghij",
NPOS, 0),
158 TEST (
"abbdefghij",
"abcdefghij",
NPOS, 0),
159 TEST (
"abcdeeghij",
"abcdefghij",
NPOS, 0),
160 TEST (
"abcdefghii",
"abcdefghij",
NPOS, 0),
162 TEST (
"bbcdefghij",
"a", 1, 0),
163 TEST (
"eeeeeeghij",
"aeeee", 1, 0),
165 TEST (
"aeeee",
"eeeeeeghij",
NPOS, 0),
167 TEST (
"bbcdefghij",
"abcdefghij", 1, 0),
168 TEST (
"abcdffghij",
"abcdefghij", 1, 0),
169 TEST (
"abcdefghjj",
"abcdefghij", 1, 0),
171 TEST (
"a\0b\0\0c",
"a\0b\0\0c", 0, 0),
172 TEST (
"abc\0\0\0",
"bac\0\0\0",
NPOS, 0),
173 TEST (
"\0ab\0\0c",
"e\0ab\0\0c",
NPOS, 0),
174 TEST (
"\0ab\0\0c",
"\0ab\0\0b", 1, 0),
176 TEST (
"a\0b",
"a\0b\0\0c",
NPOS, 0),
177 TEST (
"ab\0",
"abc\0\0\0",
NPOS, 0),
178 TEST (
"\0ab",
"e\0ab\0\0c",
NPOS, 0),
179 TEST (
"bb\0",
"ab\0\0\0c", 1, 0),
180 TEST (
"\0ac",
"\0abe\0\0c", 1, 0),
182 TEST (
"x@4096",
"x@4096", 0, 0),
184 TEST (
"x@4096",
"xxxxxx", 1, 0),
186 TEST (
"x@4096",
"a\0b", 1, 0),
188 TEST (
"a@2048b@2048",
"a@2048b@2047", 1, 0),
189 TEST (
"a@2048b@2048",
"a@2048b@2047c",
NPOS, 0),
190 TEST (
"a@2048cb@2047",
"a@2048cb@2047", 0, 0),
192 TEST (
"last",
"last", 0, 0)
203#define TEST(str, off, size, arg, res, bthrow) { \
204 __LINE__, off, size, -1, -1, -1, \
205 str, sizeof str - 1, \
206 arg, sizeof arg - 1, 0, res, bthrow \
221 TEST (
"ab", 0, 2,
"ab", 0, 0),
223 TEST (
"", 0, 0,
"", 0, 0),
224 TEST (
"", 0, 0,
"\0", 0, 0),
227 TEST (
"\0", 0, 1,
"", 1, 0),
228 TEST (
"\0", 0, 1,
"\0", 1, 0),
231 TEST (
"abcdefghij", 0, 10,
"abcdefghij", 0, 0),
232 TEST (
"abcdefghij", 0, 10,
"abcdefghi", 1, 0),
233 TEST (
"abcdefghij", 1, 9,
"abcdefghi", 1, 0),
234 TEST (
"abcdefghij", 1, 8,
"abcdefghi", 1, 0),
235 TEST (
"abcdefghij", 2, 5,
"abcdefghi", 1, 0),
236 TEST (
"abcdefghi", 0, 9,
"abcdefghij",
NPOS, 0),
238 TEST (
"abbdefghij", 0, 10,
"abcdefghij",
NPOS, 0),
239 TEST (
"abbdefghij", 1, 9,
"abcdefghij", 1, 0),
240 TEST (
"abcdeeghij", 0, 10,
"abcdefghij",
NPOS, 0),
241 TEST (
"abcdeeghij", 5, 10,
"abcdefghij", 1, 0),
242 TEST (
"abcdeeghij", 0, 5,
"abcdefghij",
NPOS, 0),
243 TEST (
"abcdefghii", 0, 10,
"abcdefghij",
NPOS, 0),
244 TEST (
"abcdefghii", 9, 10,
"abcdefghij", 1, 0),
246 TEST (
"abcdefghij", 1, 1,
"b", 0, 0),
247 TEST (
"abcdefghij", 0, 1,
"b",
NPOS, 0),
248 TEST (
"abcdefghij", 1, 4,
"bcde", 0, 0),
249 TEST (
"abcdefghij", 1, 3,
"bcde",
NPOS, 0),
251 TEST (
"bbcdefghij", 2, 4,
"a", 1, 0),
252 TEST (
"bbcdefghij", 2, 0,
"a",
NPOS, 0),
253 TEST (
"aeeeeeghij", 6, 1,
"aeeee", 1, 0),
254 TEST (
"aeeeeeghij", 0, 2,
"aeeee",
NPOS, 0),
255 TEST (
"a", 0, 2,
"bbcdefghij",
NPOS, 0),
256 TEST (
"jeeee", 1, 2,
"eeeeeeghij",
NPOS, 0),
258 TEST (
"a\0b\0\0c", 0, 6,
"a\0b\0\0c", 1, 0),
259 TEST (
"a\0b\0\0c", 0, 1,
"a\0b\0\0c", 0, 0),
260 TEST (
"abc\0\0\0", 0, 4,
"abc\0\0\0", 1, 0),
261 TEST (
"abc\0\0\0", 0, 3,
"abc\0\0\0", 0, 0),
262 TEST (
"\0af\0\0c", 0, 6,
"e\0ab\0\0c",
NPOS, 0),
263 TEST (
"\0af\0\0c", 2, 2,
"e\0ab\0\0c", 1, 0),
265 TEST (
"a\0b", 0, 3,
"a\0b\0\0c", 1, 0),
266 TEST (
"a\0b", 0, 1,
"a\0b\0\0c", 0, 0),
267 TEST (
"ab\0", 0, 5,
"abc\0\0\0",
NPOS, 0),
268 TEST (
"\0eb", 0, 5,
"e\0ab\0\0c",
NPOS, 0),
269 TEST (
"\0eb", 1, 5,
"e\0ab\0\0c", 1, 0),
271 TEST (
"x@4096", 0, 4096,
"x@4096", 0, 0),
272 TEST (
"x@4096", 1, 4096,
"x@4096",
NPOS, 0),
273 TEST (
"xx", 0, 2,
"x@4096",
NPOS, 0),
274 TEST (
"x@4096", 0, 4096,
"xxxxx", 1, 0),
275 TEST (
"x@4096", 2, 5,
"xxxxx", 0, 0),
276 TEST (
"x@4096", 5, 2,
"xxxxx",
NPOS, 0),
277 TEST (
"a\0x", 0, 3,
"x@4096",
NPOS, 0),
278 TEST (
"x@4096", 0, 10,
"x\0b", 1, 0),
279 TEST (
"x@4096", 0, 1,
"x\0b", 0, 0),
281 TEST (
"\0", 2, 0,
"", 1, 1),
282 TEST (
"a", 10, 0,
"", 1, 1),
283 TEST (
"x@4096", 4106, 0,
"", 1, 1),
285 TEST (
"last", 0, 4,
"last", 0, 0)
296#define TEST(str, off, size, arg, res, bthrow) { \
297 __LINE__, off, size, -1, -1, -1, \
298 str, sizeof str - 1, \
299 arg, sizeof arg - 1, 0, res, bthrow \
314 TEST (
"ab", 0, 2,
"ab", 0, 0),
316 TEST (
"", 0, 0,
"", 0, 0),
320 TEST (
"\0", 0, 1,
"", 1, 0),
321 TEST (
"\0", 0, 1,
"\0", 0, 0),
325 TEST (
"abcdefghij", 0, 10,
"abcdefghij", 0, 0),
326 TEST (
"abcdefghij", 0, 10,
"abcdefghi", 1, 0),
327 TEST (
"abcdefghij", 1, 9,
"abcdefghi", 1, 0),
328 TEST (
"abcdefghij", 1, 8,
"abcdefghi", 1, 0),
329 TEST (
"abcdefghij", 2, 5,
"abcdefghi", 1, 0),
330 TEST (
"abcdefghi", 0, 9,
"abcdefghij",
NPOS, 0),
332 TEST (
"abbdefghij", 0, 10,
"abcdefghij",
NPOS, 0),
333 TEST (
"abbdefghij", 1, 9,
"abcdefghij", 1, 0),
334 TEST (
"abcdeeghij", 0, 10,
"abcdefghij",
NPOS, 0),
335 TEST (
"abcdeeghij", 5, 10,
"abcdefghij", 1, 0),
336 TEST (
"abcdeeghij", 0, 5,
"abcdefghij",
NPOS, 0),
337 TEST (
"abcdefghii", 0, 10,
"abcdefghij",
NPOS, 0),
338 TEST (
"abcdefghii", 9, 10,
"abcdefghij", 1, 0),
340 TEST (
"abcdefghij", 1, 1,
"b", 0, 0),
341 TEST (
"abcdefghij", 0, 1,
"b",
NPOS, 0),
342 TEST (
"abcdefghij", 1, 4,
"bcde", 0, 0),
343 TEST (
"abcdefghij", 1, 3,
"bcde",
NPOS, 0),
345 TEST (
"bbcdefghij", 2, 4,
"a", 1, 0),
346 TEST (
"bbcdefghij", 2, 0,
"a",
NPOS, 0),
347 TEST (
"aeeeeeghij", 6, 1,
"aeeee", 1, 0),
348 TEST (
"aeeeeeghij", 0, 2,
"aeeee",
NPOS, 0),
349 TEST (
"a", 0, 2,
"bbcdefghij",
NPOS, 0),
350 TEST (
"jeeee", 1, 2,
"eeeeeeghij",
NPOS, 0),
352 TEST (
"a\0b\0\0c", 0, 6,
"a\0b\0\0c", 0, 0),
353 TEST (
"a\0b\0\0c", 2, 4,
"a\0b\0\0c", 1, 0),
354 TEST (
"e\0b\0\0c", 0, 1,
"a\0b\0\0c", 1, 0),
355 TEST (
"abc\0\0\0", 0, 4,
"abc\0\0\0",
NPOS, 0),
356 TEST (
"ab\0c\0\0", 2, 2,
"ab\0b\0\0",
NPOS, 0),
357 TEST (
"abc\0\0\0", 3, 3,
"abc\0\0\0",
NPOS, 0),
358 TEST (
"\0af\0\0c", 0, 6,
"e\0ab\0\0c",
NPOS, 0),
359 TEST (
"\0af\0\0c", 0, 1,
"\0ab\0\0ce",
NPOS, 0),
360 TEST (
"\0af\0\0c", 2, 2,
"e\0ab\0\0c", 1, 0),
361 TEST (
"\0ae\0\0c", 2, 4,
"e\0\0b\0ca", 1, 0),
363 TEST (
"a\0b", 0, 3,
"a\0b\0\0c",
NPOS, 0),
364 TEST (
"a\0b", 0, 1,
"a\0b\0\0c",
NPOS, 0),
365 TEST (
"ab\0", 0, 5,
"abc\0\0\0",
NPOS, 0),
366 TEST (
"\0eb", 0, 5,
"e\0ab\0\0c",
NPOS, 0),
367 TEST (
"a\0b\0\0c", 0, 3,
"a\0b", 0, 0),
368 TEST (
"a\0b\0\0c", 0, 1,
"a", 0, 0),
369 TEST (
"abc\0\0\0", 0, 5,
"abc\0\0", 0, 0),
370 TEST (
"e\0ab\0\0c", 0, 7,
"e\0ab\0\0c", 0, 0),
371 TEST (
"a\0b\0\0c", 2, 3,
"a\0b", 1, 0),
372 TEST (
"a\0b\0\0c", 2, 1,
"a", 1, 0),
373 TEST (
"abc\0\0\0", 2, 5,
"abc\0\0", 1, 0),
374 TEST (
"e\0ag\0\0c", 3, 6,
"e\0ab\0\0c", 1, 0),
376 TEST (
"x@4096", 0, 4096,
"x@4096", 0, 0),
377 TEST (
"x@4096", 1, 4096,
"x@4096",
NPOS, 0),
378 TEST (
"xx", 0, 2,
"x@4096",
NPOS, 0),
379 TEST (
"x@4096", 0, 4096,
"xxxxx", 1, 0),
380 TEST (
"x@4096", 2, 5,
"xxxxx", 0, 0),
381 TEST (
"x@4096", 5, 2,
"xxxxx",
NPOS, 0),
382 TEST (
"a\0x", 0, 3,
"x@4096",
NPOS, 0),
383 TEST (
"x@4096", 0, 10,
"x\0b", 1, 0),
384 TEST (
"x@4096", 0, 1,
"x\0b",
NPOS, 0),
385 TEST (
"a@4096\0", 4096, 1,
"\0", 0, 0),
387 TEST (
"\0", 2, 0,
"", 1, 1),
388 TEST (
"a", 10, 0,
"", 1, 1),
389 TEST (
"x@4096", 4106, 0,
"", 1, 1),
391 TEST (
"last", 0, 4,
"last", 0, 0)
402#define TEST(str, off, size, arg, size2, res, bthrow) { \
403 __LINE__, off, size, -1, size2, -1, \
404 str, sizeof str - 1, \
405 arg, sizeof arg - 1, 0, res, bthrow \
421 TEST (
"ab", 0, 2,
"ab", 2, 0, 0),
423 TEST (
"", 0, 0,
"", 0, 0, 0),
425 TEST (
"", 0, 0,
"a", 0, 0, 0),
428 TEST (
"\0", 0, 1,
"", 0, 1, 0),
429 TEST (
"\0", 0, 1,
"\0", 1, 0, 0),
430 TEST (
"\0", 0, 1,
"\0\0", 2,
NPOS, 0),
431 TEST (
"\0", 0, 1,
"\0\0", 1, 0, 0),
432 TEST (
"\0\0", 1, 1,
"\0", 1, 0, 0),
435 TEST (
"abcdefghij", 0, 10,
"abcdefghij", 10, 0, 0),
436 TEST (
"abcdefghij", 0, 10,
"abcdefghi", 9, 1, 0),
437 TEST (
"abcdefghij", 1, 9,
"abcdefghi", 9, 1, 0),
438 TEST (
"abcdefghij", 1, 8,
"abcdefghi", 9, 1, 0),
439 TEST (
"abcdefghij", 2, 5,
"abcdefghi", 9, 1, 0),
440 TEST (
"abcdefghi", 0, 9,
"abcdefghij", 10,
NPOS, 0),
441 TEST (
"abcdefghi", 0, 4,
"abcdefghij", 4, 0, 0),
442 TEST (
"abcdefghi", 0, 5,
"abcdefghij", 4, 1, 0),
444 TEST (
"abbdefghij", 0, 10,
"abcdefghij", 10,
NPOS, 0),
445 TEST (
"abbdefghij", 1, 9,
"abcdefghij", 10, 1, 0),
446 TEST (
"abcdeeghij", 0, 10,
"abcdefghij", 10,
NPOS, 0),
447 TEST (
"abcdeeghij", 5, 10,
"abcdefghij", 10, 1, 0),
448 TEST (
"abcdeeghij", 0, 3,
"abcdefghij", 3, 0, 0),
449 TEST (
"abcdeeghij", 0, 5,
"abcdefghij", 10,
NPOS, 0),
450 TEST (
"abcdefghii", 0, 10,
"abcdefghij", 10,
NPOS, 0),
451 TEST (
"abcdefghii", 0, 9,
"abcdefghij", 9, 0, 0),
452 TEST (
"abcdefghii", 9, 10,
"abcdefghij", 10, 1, 0),
454 TEST (
"abcdefghij", 1, 1,
"b", 1, 0, 0),
455 TEST (
"abcdefghij", 1, 1,
"g", 1,
NPOS, 0),
456 TEST (
"abcdefghij", 1, 1,
"g", 0, 1, 0),
457 TEST (
"abcdefghij", 1, 1,
"bfg", 1, 0, 0),
458 TEST (
"abcdefghij", 0, 1,
"b", 1,
NPOS, 0),
459 TEST (
"abcdefghij", 1, 4,
"bcde", 4, 0, 0),
460 TEST (
"abcdefghij", 1, 3,
"bcde", 4,
NPOS, 0),
461 TEST (
"abcdefghij", 1, 3,
"bcde", 2, 1, 0),
463 TEST (
"bbcdefghij", 2, 4,
"a", 1, 1, 0),
464 TEST (
"bbcdefghij", 2, 0,
"a", 1,
NPOS, 0),
465 TEST (
"bbcaefghij", 3, 1,
"age", 1, 0, 0),
466 TEST (
"aeeeeeghij", 6, 1,
"aeeee", 2, 1, 0),
467 TEST (
"aeeeeeghij", 0, 2,
"aeeee", 3,
NPOS, 0),
468 TEST (
"aeeeeeghij", 2, 3,
"aeeee", 5, 1, 0),
469 TEST (
"a", 0, 2,
"bbcdefghij", 10,
NPOS, 0),
470 TEST (
"jeeee", 1, 2,
"eeeeeeghij", 10,
NPOS, 0),
471 TEST (
"jeeee", 1, 4,
"eeeeeeghij", 4, 0, 0),
473 TEST (
"a\0b\0\0c", 0, 6,
"a\0b\0\0c", 6, 0, 0),
474 TEST (
"a\0b\0\0c", 2, 4,
"a\0b\0\0c", 6, 1, 0),
475 TEST (
"e\0b\0\0c", 0, 1,
"a\0b\0\0c", 6, 1, 0),
476 TEST (
"e\0b\0\0c", 3, 2,
"\0\0a\0bc", 2, 0, 0),
477 TEST (
"e\0b\0\0c", 3, 3,
"\0\0c\0ba", 4,
NPOS, 0),
478 TEST (
"abc\0\0\0", 0, 4,
"abc\0\0\0", 5,
NPOS, 0),
479 TEST (
"ab\0c\0\0", 2, 2,
"ab\0b\0\0", 4,
NPOS, 0),
480 TEST (
"abc\0\0\0", 3, 3,
"abc\0\0\0", 3,
NPOS, 0),
481 TEST (
"\0af\0\0c", 0, 6,
"e\0ab\0\0c", 6,
NPOS, 0),
482 TEST (
"\0af\0\0c", 0, 1,
"\0ab\0\0ce", 2,
NPOS, 0),
483 TEST (
"\0\0c\0af", 3, 3,
"\0ab\0\0ce", 3, 1, 0),
484 TEST (
"\0af\0\0c", 2, 2,
"e\0ab\0\0c", 2, 1, 0),
485 TEST (
"\0ae\0\0c", 2, 4,
"e\0\0b\0ca", 4, 1, 0),
487 TEST (
"a\0b", 0, 3,
"a\0b\0\0c", 4,
NPOS, 0),
488 TEST (
"a\0b", 0, 1,
"a\0b\0\0c", 2,
NPOS, 0),
489 TEST (
"ab\0", 0, 5,
"abc\0\0\0", 3,
NPOS, 0),
490 TEST (
"\0eb", 0, 5,
"e\0ab\0\0c", 1,
NPOS, 0),
491 TEST (
"a\0b\0\0c", 0, 3,
"a\0b", 3, 0, 0),
492 TEST (
"a\0b\0\0c", 0, 1,
"a", 1, 0, 0),
493 TEST (
"abc\0\0\0", 0, 5,
"abc\0\0", 5, 0, 0),
494 TEST (
"e\0ab\0\0c", 0, 7,
"e\0ab\0\0c", 7, 0, 0),
495 TEST (
"a\0b\0\0c", 2, 3,
"a\0b", 2, 1, 0),
496 TEST (
"a\0b\0\0c", 2, 1,
"a", 0, 1, 0),
497 TEST (
"abc\0\0\0", 2, 5,
"c\0\0ab", 3, 1, 0),
498 TEST (
"e\0ag\0\0c", 3, 6,
"e\0ab\0\0c", 7, 1, 0),
499 TEST (
"abc\0\0\0", 2, 5,
"c\0\0ab", 4,
NPOS, 0),
501 TEST (
"x@4096", 0, 4096,
"x@4096", 4096, 0, 0),
502 TEST (
"x@4096", 1, 4096,
"x@4096", 4096,
NPOS, 0),
503 TEST (
"x@4096", 1, 4096,
"x@4096", 4092, 1, 0),
504 TEST (
"xx", 0, 2,
"x@4096", 4092,
NPOS, 0),
505 TEST (
"x@4096", 0, 4096,
"xxxxx", 5, 1, 0),
506 TEST (
"x@4096", 4090, 5,
"xxxxx", 5, 0, 0),
507 TEST (
"x@4096", 2, 5,
"xxxxx", 5, 0, 0),
508 TEST (
"x@4096", 5, 2,
"xxxxx", 3,
NPOS, 0),
509 TEST (
"a\0x", 0, 3,
"x@4096", 10,
NPOS, 0),
510 TEST (
"x@4096", 0, 10,
"x\0b", 2, 1, 0),
511 TEST (
"x@4096", 0, 1,
"x\0b", 2,
NPOS, 0),
513 TEST (
"a@4096\0", 4096, 1,
"\0b", 1, 0, 0),
515 TEST (
"\0", 2, 0,
"", 0, 1, 1),
516 TEST (
"a", 10, 0,
"", 0, 1, 1),
517 TEST (
"x@4096", 4106, 0,
"", 0, 1, 1),
519 TEST (
"last", 0, 4,
"last", 4, 0, 0)
530#define TEST(str, off, size, arg, off2, size2, res, bthrow) { \
531 __LINE__, off, size, off2, size2, -1, \
532 str, sizeof str - 1, \
533 arg, sizeof arg - 1, 0, res, bthrow \
551 TEST (
"ab", 0, 2,
"ab", 0, 2, 0, 0),
553 TEST (
"", 0, 0,
"", 0, 0, 0, 0),
554 TEST (
"", 0, 0,
"\0", 0, 1,
NPOS, 0),
555 TEST (
"", 0, 0,
"a", 0, 0, 0, 0),
556 TEST (
"", 0, 0,
"a", 0, 1,
NPOS, 0),
558 TEST (
"\0", 0, 1,
"", 0, 0, 1, 0),
559 TEST (
"\0", 0, 1,
"\0", 0, 1, 0, 0),
560 TEST (
"\0", 0, 1,
"\0", 0, 0, 1, 0),
561 TEST (
"\0", 0, 1,
"\0\0", 0, 2,
NPOS, 0),
562 TEST (
"\0", 0, 1,
"\0\0", 1, 1, 0, 0),
563 TEST (
"\0", 0, 1,
"\0\0", 2, 2, 1, 0),
564 TEST (
"\0\0", 1, 1,
"\0", 0, 1, 0, 0),
565 TEST (
"\0", 0, 1,
"a", 0, 1,
NPOS, 0),
567 TEST (
"abcdefghij", 0, 10,
"abcdefghij", 0, 10, 0, 0),
568 TEST (
"abcdefghij", 0, 10,
"abcdefghij", 1, 10,
NPOS, 0),
569 TEST (
"abcdefghij", 0, 10,
"abcdefghi", 0, 9, 1, 0),
570 TEST (
"abcdefghij", 5, 4,
"abcdefghi", 5, 9, 0, 0),
571 TEST (
"abcdefghij", 1, 9,
"abcdefghi", 0, 9, 1, 0),
572 TEST (
"abcdefghij", 1, 9,
"abcdefghi", 1, 8, 1, 0),
573 TEST (
"abcdefghij", 1, 8,
"abcdefghi", 0, 9, 1, 0),
574 TEST (
"abcdefghij", 1, 8,
"abcdefghi", 2, 9,
NPOS, 0),
575 TEST (
"abcdefghij", 2, 5,
"abcdefghi", 0, 9, 1, 0),
576 TEST (
"abcdefghij", 2, 5,
"abcdefghi", 2, 5, 0, 0),
577 TEST (
"abcdefghi", 0, 9,
"abcdefghij", 0, 10,
NPOS, 0),
578 TEST (
"abcdefghi", 0, 9,
"abcdefghij", 3, 10,
NPOS, 0),
579 TEST (
"abcdefghi", 0, 4,
"abcdefghij", 0, 4, 0, 0),
580 TEST (
"abcdefghi", 0, 4,
"abcdefghij", 9, 1,
NPOS, 0),
581 TEST (
"abcdefghi", 0, 5,
"abcdefghij", 0, 4, 1, 0),
583 TEST (
"abbdefghij", 0, 10,
"abcdefghij", 0, 10,
NPOS, 0),
584 TEST (
"abbdefghij", 0, 10,
"abcdefghij", 1, 2,
NPOS, 0),
585 TEST (
"abbdefghij", 1, 9,
"abcdefghij", 0, 10, 1, 0),
586 TEST (
"abbdefghij", 1, 9,
"abcdefghij", 5, 10,
NPOS, 0),
587 TEST (
"abcdeeghij", 0, 10,
"abcdefghij", 0, 10,
NPOS, 0),
588 TEST (
"abcdeeghij", 0, 10,
"abcdefghij", 1, 5,
NPOS, 0),
589 TEST (
"abcdeeghij", 5, 10,
"abcdefghij", 0, 10, 1, 0),
590 TEST (
"abcdeeghij", 0, 3,
"abcdefghij", 0, 3, 0, 0),
591 TEST (
"abcdeeghij", 0, 5,
"abcdefghij", 0, 10,
NPOS, 0),
592 TEST (
"abcdeeghij", 0, 5,
"abcdeabcde", 5, 10, 0, 0),
593 TEST (
"abcdefghii", 0, 10,
"abcdefghij", 0, 10,
NPOS, 0),
594 TEST (
"abcdefghii", 0, 10,
"abcdefghij", 8, 2,
NPOS, 0),
595 TEST (
"abcdefghii", 0, 9,
"abcdefghij", 0, 9, 0, 0),
596 TEST (
"abcdefghii", 9, 10,
"abcdefghij", 0, 10, 1, 0),
597 TEST (
"abcdefghii", 9, 10,
"abcdefghij", 9, 10,
NPOS, 0),
599 TEST (
"abcdefghij", 1, 1,
"b", 0, 1, 0, 0),
600 TEST (
"abcdefghij", 1, 1,
"g", 0, 1,
NPOS, 0),
601 TEST (
"abcdefghij", 1, 1,
"g", 0, 0, 1, 0),
602 TEST (
"abcdefghij", 1, 1,
"bfg", 0, 1, 0, 0),
603 TEST (
"abcdefghij", 1, 1,
"bfg", 2, 1,
NPOS, 0),
604 TEST (
"abcdefghij", 0, 1,
"b", 0, 1,
NPOS, 0),
605 TEST (
"abcdefghij", 1, 4,
"bcde", 0, 4, 0, 0),
606 TEST (
"abcdefghij", 1, 4,
"bcde", 2, 4,
NPOS, 0),
607 TEST (
"abcdefghij", 1, 3,
"bcde", 0, 4,
NPOS, 0),
608 TEST (
"abcdefghij", 1, 3,
"aebcd", 2, 3, 0, 0),
609 TEST (
"abcdefghij", 1, 3,
"bcde", 0, 2, 1, 0),
610 TEST (
"abcdefghij", 1, 3,
"bcde", 1, 2,
NPOS, 0),
612 TEST (
"bbcdefghij", 2, 4,
"a", 0, 1, 1, 0),
613 TEST (
"bbcdefghij", 2, 0,
"a", 0, 1,
NPOS, 0),
614 TEST (
"bbcaefghij", 3, 1,
"age", 0, 1, 0, 0),
615 TEST (
"aeeeeeghij", 6, 1,
"aeeee", 0, 2, 1, 0),
616 TEST (
"aeeeeeghij", 0, 2,
"aeeee", 0, 3,
NPOS, 0),
617 TEST (
"aeeeeeghij", 2, 3,
"aeeee", 0, 5, 1, 0),
618 TEST (
"aeeeeeghij", 2, 3,
"eeeea", 1, 3, 0, 0),
619 TEST (
"a", 0, 2,
"bbcdefghij", 0, 10,
NPOS, 0),
620 TEST (
"jeeee", 1, 2,
"eeeeeeghij", 0, 10,
NPOS, 0),
621 TEST (
"jeeee", 1, 2,
"eeeeeeghij", 1, 1, 1, 0),
622 TEST (
"jeeee", 1, 4,
"eeeeeeghij", 0, 4, 0, 0),
624 TEST (
"a\0b\0\0c", 0, 6,
"a\0b\0\0c", 0, 6, 0, 0),
625 TEST (
"a\0b\0\0c", 1, 1,
"a\0b\0\0c", 3, 1, 0, 0),
626 TEST (
"a\0b\0\0c", 2, 4,
"a\0b\0\0c", 0, 6, 1, 0),
627 TEST (
"a\0b\0\0c", 2, 4,
"ab\0\0c\0", 1, 4, 0, 0),
628 TEST (
"e\0b\0\0c", 0, 1,
"a\0b\0\0c", 0, 6, 1, 0),
629 TEST (
"e\0b\0\0c", 3, 2,
"\0\0a\0bc", 0, 2, 0, 0),
630 TEST (
"e\0b\0\0c", 3, 3,
"\0\0c\0ba", 0, 4,
NPOS, 0),
631 TEST (
"e\0b\0\0c", 3, 3,
"a\0\0c\0b", 1, 3, 0, 0),
632 TEST (
"abc\0\0\0", 0, 4,
"abc\0\0\0", 0, 5,
NPOS, 0),
633 TEST (
"abc\0\0\0", 3, 4,
"a\0\0\0bc", 1, 3, 0, 0),
634 TEST (
"ab\0c\0\0", 2, 2,
"ab\0b\0\0", 0, 4,
NPOS, 0),
635 TEST (
"ab\0c\0\0", 2, 4,
"ab\0b\0\0", 2, 4, 1, 0),
636 TEST (
"\0af\0\0c", 0, 6,
"e\0ab\0\0c", 0, 6,
NPOS, 0),
637 TEST (
"\0af\0\0c", 2, 6,
"e\0ab\0\0c", 2, 6, 1, 0),
638 TEST (
"\0af\0\0c", 0, 1,
"\0ab\0\0ce", 0, 2,
NPOS, 0),
639 TEST (
"\0af\0\0c", 3, 1,
"\0ab\0\0ce", 0, 1, 0, 0),
640 TEST (
"\0\0c\0af", 3, 3,
"\0ab\0\0ce", 0, 3, 1, 0),
641 TEST (
"\0\0c\0af", 1, 2,
"\0ab\0\0ec", 4, 3,
NPOS, 0),
642 TEST (
"\0af\0\0c", 2, 2,
"e\0ab\0\0c", 0, 2, 1, 0),
643 TEST (
"\0ae\0\0c", 0, 3,
"e\0\0b\0ca", 4, 4,
NPOS, 0),
645 TEST (
"a\0b", 0, 3,
"a\0b\0\0c", 0, 4,
NPOS, 0),
646 TEST (
"a\0b", 1, 3,
"a\0b\0\0c", 4, 4,
NPOS, 0),
647 TEST (
"a\0b", 0, 1,
"a\0b\0\0c", 0, 2,
NPOS, 0),
648 TEST (
"ab\0", 0, 5,
"abc\0\0\0", 0, 3,
NPOS, 0),
649 TEST (
"ab\0", 2, 1,
"abc\0\0\0", 3, 3,
NPOS, 0),
650 TEST (
"\0eb", 0, 5,
"e\0ab\0\0c", 0, 1,
NPOS, 0),
651 TEST (
"a\0b\0\0c", 0, 3,
"a\0b", 0, 3, 0, 0),
652 TEST (
"a\0b\0\0c", 3, 2,
"a\0b", 1, 2,
NPOS, 0),
653 TEST (
"a\0b\0\0c", 0, 1,
"a", 0, 1, 0, 0),
654 TEST (
"abc\0\0\0", 0, 5,
"abc\0\0", 0, 5, 0, 0),
655 TEST (
"e\0ab\0\0c", 0, 7,
"e\0ab\0\0c", 0, 7, 0, 0),
656 TEST (
"e\0ab\0\0c", 0, 7,
"e\0ab\0\0c", 2, 7, 1, 0),
657 TEST (
"a\0b\0\0c", 2, 3,
"a\0b", 0, 2, 1, 0),
658 TEST (
"a\0b\0\0c", 2, 1,
"a", 0, 0, 1, 0),
659 TEST (
"abc\0\0\0", 2, 5,
"c\0\0ab", 0, 3, 1, 0),
660 TEST (
"e\0ag\0\0c", 3, 6,
"e\0ab\0\0c", 0, 7, 1, 0),
661 TEST (
"abc\0\0\0", 2, 5,
"c\0\0ab", 0, 4,
NPOS, 0),
663 TEST (
"x@4096", 0, 4096,
"x@4096", 0, 4096, 0, 0),
664 TEST (
"x@4096", 1, 4096,
"x@4096", 0, 4096,
NPOS, 0),
665 TEST (
"x@4096", 1, 4096,
"x@4096", 0, 4092, 1, 0),
666 TEST (
"x@4096", 1, 4090,
"x@4096", 2, 4090, 0, 0),
667 TEST (
"x@4096", 1, 4102,
"x@4096", 2, 4102, 1, 0),
668 TEST (
"xx", 0, 2,
"x@4096", 0, 4092,
NPOS, 0),
669 TEST (
"xx", 0, 2,
"x@4096", 4090, 2, 0, 0),
670 TEST (
"x@4096", 0, 4096,
"xxxxx", 0, 5, 1, 0),
671 TEST (
"x@4096", 4090, 5,
"xxxxx", 0, 5, 0, 0),
672 TEST (
"x@4096", 2, 5,
"xxxxx", 0, 5, 0, 0),
673 TEST (
"x@4096", 5, 2,
"xxxxx", 0, 3,
NPOS, 0),
674 TEST (
"a\0x", 0, 3,
"x@4096", 0, 10,
NPOS, 0),
675 TEST (
"a\0x", 2, 1,
"x@4096", 4095, 1, 0, 0),
676 TEST (
"x@4096", 0, 10,
"x\0b", 0, 2, 1, 0),
677 TEST (
"x@4096", 0, 1,
"x\0b", 0, 2,
NPOS, 0),
679 TEST (
"a@4096\0", 4096, 1,
"b\0", 1, 1, 0, 0),
681 TEST (
"\0", 2, 0,
"", 0, 0, 1, 1),
682 TEST (
"a", 10, 0,
"", 0, 0, 1, 1),
683 TEST (
"x@4096", 4106, 0,
"", 0, 0, 1, 1),
685 TEST (
"", 0, 0,
"\0", 2, 0, 1, 2),
686 TEST (
"", 0, 0,
"a", 10, 0, 1, 2),
687 TEST (
"", 0, 0,
"x@4096", 4106, 0, 1, 2),
689 TEST (
"last", 0, 4,
"last", 0, 4, 0, 0)
694template <
class charT,
class Traits,
class Allocator>
699 typedef std::basic_string <charT, Traits, Allocator>
String;
702 static const std::size_t BUFSIZE = 256;
704 static charT wstr_buf [BUFSIZE];
705 static charT warg_buf [BUFSIZE];
707 std::size_t str_len =
sizeof wstr_buf /
sizeof *wstr_buf;
708 std::size_t arg_len =
sizeof warg_buf /
sizeof *warg_buf;
718 if (wstr != wstr_buf)
721 if (warg != warg_buf)
735 const charT*
const arg_ptr = tcase.
arg ?
arg.c_str () :
str.c_str ();
738 std::size_t total_compare_calls = 0;
739 std::size_t n_compare_calls = 0;
740 std::size_t*
const rg_calls =
744 total_compare_calls = rg_calls[UTMemFun::compare];
747 const char* expected = 0;
750#ifndef _RWSTD_NO_EXCEPTIONS
753 expected = exceptions [1];
754 else if ( 2 == tcase.
bthrow
755 &&
Compare (size_size_cstr_size_size) ==
func.which_)
756 expected = exceptions [1];
757 else if (3 == tcase.
bthrow)
758 expected = exceptions [2];
768 switch (
func.which_) {
770 res =
str.compare (arg_ptr);
774 res =
str.compare (arg_str);
776 n_compare_calls = rg_calls[UTMemFun::compare];
787 case Compare (size_size_cptr_size):
789 arg_ptr, tcase.
size2);
792 case Compare (size_size_cstr_size_size):
798 RW_ASSERT (
"test logic error: unknown compare overload");
803 const bool success = (
res < 0 && tcase.
nres ==
NPOS)
805 || (
res == 0 && tcase.
nres == 0);
808 "line %d. %{$FUNCALL} == %d, got %d",
813 rw_assert (n_compare_calls - total_compare_calls > 0,
814 0, tcase.
line,
"line %d. %{$FUNCALL} doesn't "
815 "use traits::compare()", __LINE__);
819#ifndef _RWSTD_NO_EXCEPTIONS
821 catch (
const std::out_of_range &ex) {
824 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
825 "unexpectedly%{;} caught std::%s(%#s)",
826 __LINE__, 0 != expected, expected,
caught, ex.what ());
828 catch (
const std::length_error &ex) {
831 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
832 "unexpectedly%{;} caught std::%s(%#s)",
833 __LINE__, 0 != expected, expected,
caught, ex.what ());
838 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
839 "unexpectedly%{;} caught std::%s(%#s)",
840 __LINE__, 0 != expected, expected,
caught, ex.what ());
845 "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
846 "unexpectedly%{;} caught %s",
847 __LINE__, 0 != expected, expected,
caught);
865int main (
int argc,
char** argv)
872 Compare (sig), sig ## _test_cases, \
873 sizeof sig ## _test_cases / sizeof *sig ## _test_cases \
878 TEST (size_size_cptr),
879 TEST (size_size_cstr),
880 TEST (size_size_cptr_size),
881 TEST (size_size_cstr_size_size)
884 const std::size_t test_count =
sizeof tests /
sizeof *tests;
887 "lib.string.compare",
#define TEST(str, arg, res, bthrow)
void test_compare(charT, Traits *, Allocator *, const StringFunc &func, const StringTestCase &tcase)
#define size_size_cptr_test_cases
#define size_size_cstr_test_cases
#define size_size_cptr_size_test_cases
#define size_size_cstr_size_size_test_cases
std::char_traits< S > Traits
_TEST_EXPORT char * rw_expand(char *, const char *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX, _RWSTD_SIZE_T *=0)
_RWSTD_SIZE_T * rw_get_call_counters(std::char_traits< charT > *, charT *)
_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