Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
rw_strings.h
Go to the documentation of this file.
1
27#ifndef RW_21_STRINGS_H_INCLUDED
28#define RW_21_STRINGS_H_INCLUDED
29
30#include <rw_char.h> // for rw_expand()
31#include <rw_testdefs.h>
32#include <rw_containers.h> // for ContainerIds
33
34
36// defines enumerations identifying basic_string template arguments,
37// sets of overloaded functions, member types used in the declarations
38// of their signatures, and specific overloads of such member functions
40
41 // identifiers for the charT template argument
42 enum CharId { Char, WChar, UChar };
43
44 // identifiers for the Traits template argument
46
47 // identifies a set of overloaded member or non-member
48 // string functions
49 enum FuncId {
50 // 6 bits, 64 functions max
51 /* 0 */ fid_append,
52 /* 1 */ fid_assign,
53 /* 2 */ fid_erase,
54 /* 3 */ fid_insert,
55 /* 4 */ fid_replace,
57 /* 6 */ fid_find,
58 /* 7 */ fid_rfind,
63 /* 12 */ fid_compare,
64 /* 13 */ fid_substr,
65 /* 14 */ fid_op_index,
67 /* 15 */ fid_at,
69 /* 16 */ fid_copy,
70 /* 17 */ fid_ctor,
71 /* 18 */ fid_op_set,
72 /* 19 */ fid_swap,
73 /* 20 */ fid_push_back,
74 /* 21 */ fid_op_plus,
75 /* 22 */ fid_op_equal,
77 /* 24 */ fid_op_less,
81 /* 28 */ fid_size,
82 /* 29 */ fid_length,
83 /* 30 */ fid_max_size,
84 /* 31 */ fid_resize,
85 /* 32 */ fid_capacity,
86 /* 33 */ fid_reserve,
87 /* 34 */ fid_clear,
88 /* 35 */ fid_empty,
89 /* 36 */ fid_begin,
91 /* 37 */ fid_end,
93 /* 38 */ fid_rbegin,
95 /* 39 */ fid_rend,
97 /* 40 */ fid_c_str,
98 /* 41 */ fid_data,
101 /* 44 */ fid_inserter,
102 /* 45 */ fid_getline,
103 /* -- */ fid_bits = 6,
104 /* -- */ fid_mask = 63
105 };
106
107 // identifies the type of a function argument, including
108 // the implicit this
109 enum ArgId {
110 // 4 bits, 16 types max
111 /* 0 */ arg_void, // void
112 /* 1 */ arg_size, // size_type
113 /* 2 */ arg_val, // value_type
114 /* 3 */ arg_ptr, // pointer
115 /* 4 */ arg_cptr, // const_pointer
116 /* 5 */ arg_ref, // reference
117 /* 6 */ arg_cref, // const_reference
118 /* 7 */ arg_iter, // iterator
119 /* 8 */ arg_citer, // const_iterator
120 /* 9 */ arg_range, // Iterator, Iterator
121 /* 10 */ arg_str, // string& (or this for member functions)
122 /* 11 */ arg_cstr, // const string& (or const this for members)
123 /* 12 */ arg_alloc, // const allocator&
124 /* 13 */ arg_istream, // istream&
125 /* 14 */ arg_ostream, // ostream&
126 /* -- */ arg_bits = 4,
127 /* -- */ arg_mask = 15
128 };
129
130 enum {
131 // bit designating a member function
132 bit_member = 1 << (fid_bits + 6 * arg_bits)
133 };
134
135// define the helper macros
136#include <rw_sigdefs.h>
137
138 // unique identifiers for all overloads of each member function
139 // 6 bits for FuncId
140 // 6 * 4 bits for ArgId (at most 6 arguments including this)
141 // 1 bit for membership
144 // append (const_pointer)
146 // append (const basic_string&)
147 MEMBER_1 (append, str, cstr),
148 // append (const_pointer, size_type)
150 // append (const basic_string&, size_type, size_type)
152 // append (size_type, value_type)
154 // append (InputIterator, InputIterator)
155 MEMBER_1 (append, str, range),
156
158 // assign (const_pointer)
159 MEMBER_1 (assign, str, cptr),
160 // assign (const basic_string&)
161 MEMBER_1 (assign, str, cstr),
162 // assign (const_pointer, size_type)
163 MEMBER_2 (assign, str, cptr, size),
164 // assign (const basic_string&, size_type, size_type)
165 MEMBER_3 (assign, str, cstr, size, size),
166 // assign (size_type, value_type)
168 // assign (InputIterator, InputIterator)
169 MEMBER_1 (assign, str, range),
170
172 // erase ()
173 MEMBER_0 (erase, str),
174 // erase (size_type)
175 MEMBER_1 (erase, str, size),
176 // erase (size_type, size_type)
177 MEMBER_2 (erase, str, size, size),
178 // erase (iterator)
179 MEMBER_1 (erase, str, iter),
180 // erase (iterator, iterator)
181 MEMBER_2 (erase, str, iter, iter),
182
184 // insert (size_type, const_pointer)
185 MEMBER_2 (insert, str, size, cptr),
186 // insert (size_type, const basic_string&)
187 MEMBER_2 (insert, str, size, cstr),
188 // insert (size_type, const_pointer, size_type)
189 MEMBER_3 (insert, str, size, cptr, size),
190 // insert (size_type, const basic_string&, size_type, size_type)
191 MEMBER_4 (insert, str, size, cstr, size, size),
192 // insert (size_type, size_type, value_type)
193 MEMBER_3 (insert, str, size, size, val),
194 // insert (iterator, value_type)
195 MEMBER_2 (insert, str, iter, val),
196 // insert (iterator, size_type, value_type)
197 MEMBER_3 (insert, str, iter, size, val),
198 // insert (iterator, InputIterator, InputIterator)
199 MEMBER_2 (insert, str, iter, range),
200
202 // (size_type, size_type, const_pointer)
203 MEMBER_3 (replace, str, size, size, cptr),
204 // (size_type, size_type, const basic_string&)
205 MEMBER_3 (replace, str, size, size, cstr),
206 // (size_type, size_type, const_pointer, size_type)
207 MEMBER_4 (replace, str, size, size, cptr, size),
208 // (size_type, size_type, const basic_string&, size_type, size_type)
209 MEMBER_5 (replace, str, size, size, cstr, size, size),
210 // (size_type, size_type, size_type, value_type)
211 MEMBER_4 (replace, str, size, size, size, val),
212 // (iterator, iterator, const_pointer)
213 MEMBER_3 (replace, str, iter, iter, cptr),
214 // (iterator, iterator, const basic_string&)
215 MEMBER_3 (replace, str, iter, iter, cstr),
216 // (iterator, iterator, const_pointer, size_type)
217 MEMBER_4 (replace, str, iter, iter, cptr, size),
218 // (iterator, iterator, size_type, value_type)
219 MEMBER_4 (replace, str, iter, iter, size, val),
220 // (iterator, iterator, InputIterator, InputIterator)
221 MEMBER_3 (replace, str, iter, iter, range),
222
224 // operator+= (const_pointer)
225 MEMBER_1 (op_plus_eq, str, cptr),
226 // operator+= (const basic_string&)
227 MEMBER_1 (op_plus_eq, str, cstr),
228 // operator+= (value_type)
229 MEMBER_1 (op_plus_eq, str, val),
230
232 // overloads of find, rfind, find_first_of, find_last_of,
233 // find_first_not_of, find_last_not_of
234
235 // find (const_pointer) const
236 MEMBER_1 (find, cstr, cptr),
237 // find (const basic_string&) const
238 MEMBER_1 (find, cstr, cstr),
239 // find (const_pointer, size_type) const
240 MEMBER_2 (find, cstr, cptr, size),
241 // find (const_pointer, size_type, size_type) const
242 MEMBER_3 (find, cstr, cptr, size, size),
243 // find (const basic_string&, size_type) const
244 MEMBER_2 (find, cstr, cstr, size),
245 // find (value_type) const
246 MEMBER_1 (find, cstr, val),
247 // find (value_type, size_type) const
248 MEMBER_2 (find, cstr, val, size),
249
251 // rfind (const_pointer) const
252 MEMBER_1 (rfind, cstr, cptr),
253 // rfind (const basic_string&) const
254 MEMBER_1 (rfind, cstr, cstr),
255 // rfind (const_pointer, size_type) const
256 MEMBER_2 (rfind, cstr, cptr, size),
257 // rfind (const_pointer, size_type, size_type) const
258 MEMBER_3 (rfind, cstr, cptr, size, size),
259 // rfind (const basic_string&, size_type) const
260 MEMBER_2 (rfind, cstr, cstr, size),
261 // rfind (value_type) const
262 MEMBER_1 (rfind, cstr, val),
263 // rfind (value_type, size_type) const
264 MEMBER_2 (rfind, cstr, val, size),
265
267 // find_first_of (const_pointer) const
268 MEMBER_1 (find_first_of, cstr, cptr),
269 // find_first_of (const basic_string&) const
270 MEMBER_1 (find_first_of, cstr, cstr),
271 // find_first_of (const_pointer, size_type) const
272 MEMBER_2 (find_first_of, cstr, cptr, size),
273 // find_first_of (const_pointer, size_type, size_type) const
274 MEMBER_3 (find_first_of, cstr, cptr, size, size),
275 // find_first_of (const basic_string&, size_type) const
276 MEMBER_2 (find_first_of, cstr, cstr, size),
277 // find_first_of (value_type) const
278 MEMBER_1 (find_first_of, cstr, val),
279 // find_first_of (value_type, size_type) const
280 MEMBER_2 (find_first_of, cstr, val, size),
281
283 // find_last_of (const_pointer) const
284 MEMBER_1 (find_last_of, cstr, cptr),
285 // find_last_of (const basic_string&) const
286 MEMBER_1 (find_last_of, cstr, cstr),
287 // find_last_of (const_pointer, size_type) const
288 MEMBER_2 (find_last_of, cstr, cptr, size),
289 // find_last_of (const_pointer, size_type, size_type) const
290 MEMBER_3 (find_last_of, cstr, cptr, size, size),
291 // find_last_of (const basic_string&, size_type) const
292 MEMBER_2 (find_last_of, cstr, cstr, size),
293 // find_last_of (value_type) const
294 MEMBER_1 (find_last_of, cstr, val),
295 // find_last_of (value_type, size_type) const
296 MEMBER_2 (find_last_of, cstr, val, size),
297
299 // find_first_not_of (const_pointer) const
300 MEMBER_1 (find_first_not_of, cstr, cptr),
301 // find_first_not_of (const basic_string&) const
302 MEMBER_1 (find_first_not_of, cstr, cstr),
303 // find_first_not_of (const_pointer, size_type) const
304 MEMBER_2 (find_first_not_of, cstr, cptr, size),
305 // find_first_not_of (const_pointer, size_type, size_type) const
306 MEMBER_3 (find_first_not_of, cstr, cptr, size, size),
307 // find_first_not_of (const basic_string&, size_type) const
308 MEMBER_2 (find_first_not_of, cstr, cstr, size),
309 // find_first_not_of (value_type) const
310 MEMBER_1 (find_first_not_of, cstr, val),
311 // find_first_not_of (value_type, size_type) const
312 MEMBER_2 (find_first_not_of, cstr, val, size),
313
315 // find_last_not_of (const_pointer) const
316 MEMBER_1 (find_last_not_of, cstr, cptr),
317 // find_last_not_of (const basic_string&) const
318 MEMBER_1 (find_last_not_of, cstr, cstr),
319 // find_last_not_of (const_pointer, size_type) const
320 MEMBER_2 (find_last_not_of, cstr, cptr, size),
321 // find_last_not_of (const_pointer, size_type, size_type) const
322 MEMBER_3 (find_last_not_of, cstr, cptr, size, size),
323 // find_last_not_of (const basic_string&, size_type) const
324 MEMBER_2 (find_last_not_of, cstr, cstr, size),
325 // find_last_not_of (value_type) const
326 MEMBER_1 (find_last_not_of, cstr, val),
327 // find_last_not_of (value_type, size_type) const
328 MEMBER_2 (find_last_not_of, cstr, val, size),
329
331 // compare (const_pointer) const
332 MEMBER_1 (compare, cstr, cptr),
333 // compare (const basic_string&) const
334 MEMBER_1 (compare, cstr, cstr),
335 // compare (size_type, size_type, const_pointer) const
336 MEMBER_3 (compare, cstr, size, size, cptr),
337 // compare (size_type, size_type, const basic_string&) const
338 MEMBER_3 (compare, cstr, size, size, cstr),
339 // compare (size_type, size_type, const_pointer, size_type) const
340 MEMBER_4 (compare, cstr, size, size, cptr, size),
341 // compare (size_type, size_type, const basic_string&,
342 // size_type, size_type) const
343 MEMBER_5 (compare, cstr, size, size, cstr, size, size),
344
346 // substr (void) const
347 MEMBER_0 (substr, cstr),
348 // substr (size_type) const
349 MEMBER_1 (substr, cstr, size),
350 // substr (size_type, size_type) const
351 MEMBER_2 (substr, cstr, size, size),
352
354 // operator[] (size_type)
355 MEMBER_1 (op_index, str, size),
356 // operator[] (size_type) const
357 MEMBER_1 (op_index_const, cstr, size),
358 // at (size_type)
359 MEMBER_1 (at, str, size),
360 // at (size_type) const
361 MEMBER_1 (at_const, cstr, size),
362
364 // copy (pointer, size_type) const
365 MEMBER_2 (copy, cstr, ptr, size),
366 // copy (pointer, size_type, size_type) const
367 MEMBER_3 (copy, cstr, ptr, size, size),
368
370 // basic_string (void)
371 MEMBER_0 (ctor, str),
372 // basic_string (const allocator_type&)
373 MEMBER_1 (ctor, str, alloc),
374 // basic_string (const_pointer)
375 MEMBER_1 (ctor, str, cptr),
376 // basic_string (const_pointer, const allocator_type&)
377 MEMBER_2 (ctor, str, cptr, alloc),
378 // basic_string (const basic_string&)
379 MEMBER_1 (ctor, str, cstr),
380 // basic_string (const_pointer, size_type)
381 MEMBER_2 (ctor, str, cptr, size),
382 // basic_string (const_pointer, size_type, const allocator_type&)
383 MEMBER_3 (ctor, str, cptr, size, alloc),
384 // basic_string (const basic_string&, size_type)
385 MEMBER_2 (ctor, str, cstr, size),
386 // basic_string (const basic_string&, size_type, const allocator&)
387 MEMBER_3 (ctor, str, cstr, size, alloc),
388 // basic_string (const basic_string&, size_type, size_type)
389 MEMBER_3 (ctor, str, cstr, size, size),
390 // basic_string (const basic_string&, size_type, size_type, allocator&)
391 MEMBER_4 (ctor, str, cstr, size, size, alloc),
392 // basic_string (size_type, value_type)
393 MEMBER_2 (ctor, str, size, val),
394 // basic_string (size_type, value_type, const allocator_type&)
395 MEMBER_3 (ctor, str, size, val, alloc),
396 // basic_string (InputIterator, InputIterator)
397 MEMBER_1 (ctor, str, range),
398 // basic_string (InputIterator, InputIterator, const allocator&)
399 MEMBER_2 (ctor, str, range, alloc),
400
402 // operator= (const_pointer)
403 MEMBER_1 (op_set, str, cptr),
404 // operator= (const basic_string&)
405 MEMBER_1 (op_set, str, cstr),
406 // operator= (value_type)
407 MEMBER_1 (op_set, str, val),
408
410 // swap (basic_string&)
411 MEMBER_1 (swap, str, str),
412
414 // push_back (value_type)
415 MEMBER_1 (push_back, str, val),
416
418 // operator+ (const_pointer, const basic_string&)
419 NON_MEMBER_2 (op_plus, cptr, cstr),
420 // operator+ (const basic_string&, const basic_string&)
421 NON_MEMBER_2 (op_plus, cstr, cstr),
422 // operator+ (const basic_string&, const_pointer)
423 NON_MEMBER_2 (op_plus, cstr, cptr),
424 // operator+ (const basic_string&, value_type)
425 NON_MEMBER_2 (op_plus, cstr, val),
426 // operator+ (value_type, const basic_string&)
427 NON_MEMBER_2 (op_plus, val, cstr),
428
430 // operator== (const_pointer, const basic_string&)
431 NON_MEMBER_2 (op_equal, cptr, cstr),
432 // operator== (const basic_string&, const basic_string&)
433 NON_MEMBER_2 (op_equal, cstr, cstr),
434 // operator== (const basic_string&, const_pointer)
435 NON_MEMBER_2 (op_equal, cstr, cptr),
436
438 // operator!= (const_pointer, const basic_string&)
439 NON_MEMBER_2 (op_not_equal, cptr, cstr),
440 // operator!= (const basic_string&, const basic_string&)
441 NON_MEMBER_2 (op_not_equal, cstr, cstr),
442 // operator!= (const basic_string&, const_pointer)
443 NON_MEMBER_2 (op_not_equal, cstr, cptr),
444
446 // operator< (const_pointer, const basic_string&)
447 NON_MEMBER_2 (op_less, cptr, cstr),
448 // operator< (const basic_string&, const basic_string&)
449 NON_MEMBER_2 (op_less, cstr, cstr),
450 // operator< (const basic_string&, const_pointer)
451 NON_MEMBER_2 (op_less, cstr, cptr),
452
454 // operator<= (const_pointer, const basic_string&)
455 NON_MEMBER_2 (op_less_equal, cptr, cstr),
456 // operator<= (const basic_string&, const basic_string&)
457 NON_MEMBER_2 (op_less_equal, cstr, cstr),
458 // operator<= (const basic_string&, const_pointer)
459 NON_MEMBER_2 (op_less_equal, cstr, cptr),
460
462 // operator> (const_pointer, const basic_string&)
463 NON_MEMBER_2 (op_greater, cptr, cstr),
464 // operator> (const basic_string&, const basic_string&)
465 NON_MEMBER_2 (op_greater, cstr, cstr),
466 // operator> (const basic_string&, const_pointer)
467 NON_MEMBER_2 (op_greater, cstr, cptr),
468
470 // operator>= (const_pointer, const basic_string&)
471 NON_MEMBER_2 (op_greater_equal, cptr, cstr),
472 // operator>= (const basic_string&, const basic_string&)
473 NON_MEMBER_2 (op_greater_equal, cstr, cstr),
474 // operator>= (const basic_string&, const_pointer)
475 NON_MEMBER_2 (op_greater_equal, cstr, cptr),
476
478 // size () const
479 MEMBER_0 (size, cstr),
480
482 // length () const
483 MEMBER_0 (length, cstr),
484
486 // max_size () const
487 MEMBER_0 (max_size, cstr),
488
490 // resize (size_type, value_type)
491 MEMBER_2 (resize, str, size, val),
492 // resize (size_type)
493 MEMBER_1 (resize, str, size),
494
496 // capacity () const
497 MEMBER_0 (capacity, cstr),
498
500 // reserve (size_type)
501 MEMBER_1 (reserve, str, size),
502 // reserve ()
503 MEMBER_0 (reserve, str),
504
506 // clear ()
507 MEMBER_0 (clear, str),
508
510 // empty () const
511 MEMBER_0 (empty, cstr),
512
514 // begin ()
515 MEMBER_0 (begin, str),
516 // begin () const
517 MEMBER_0 (begin_const, cstr),
518 // end ()
519 MEMBER_0 (end, str),
520 // end () const
521 MEMBER_0 (end_const, cstr),
522
524 // rbegin ()
525 MEMBER_0 (rbegin, str),
526 // rbegin () const
527 MEMBER_0 (rbegin_const, cstr),
528 // rend ()
529 MEMBER_0 (rend, str),
530 // rend () const
531 MEMBER_0 (rend_const, cstr),
532
534 // c_str () const
535 MEMBER_0 (c_str, cstr),
536 // data () const
537 MEMBER_0 (data, cstr),
538
540 // get_allocator () const
541 MEMBER_0 (get_allocator, cstr),
542
544 // operator>> (istream&, basic_string&)
545 NON_MEMBER_2 (extractor, istream, str),
546 // operator<< (ostream&, const basic_string&)
547 NON_MEMBER_2 (inserter, ostream, cstr),
548
550 // getline (istream&, basic_string&)
551 NON_MEMBER_2 (getline, istream, str),
552 // getline (istream&, basic_string&, value_type)
553 NON_MEMBER_3 (getline, istream, str, val)
554 };
555
556// clean up helper macros used above
557#include <rw_sigdefs.h>
558
559 static ArgId arg_type (OverloadId id, int argno) {
560 return ArgId (((int (id) >> fid_bits) >> argno * arg_bits) & arg_mask);
561 }
562};
563
564
566static const _RWSTD_SIZE_T
567NPOS = _RWSTD_SIZE_MAX;
568
569
572{
578};
579
580
581// describes a single test case for any overload of any string
582// function (the same test case can be used to exercise more
583// than one overload of the same function)
585{
586 int line; // test case line number
587
588 int off; // offset (position argument)
589 int size; // size (count argument)
590
591 int off2; // offset 2 (position argument)
592 int size2; // size 2 (count argument)
593
594 int val; // value (single character to append)
595
596 const char* str; // controlled sequence
597 _RWSTD_SIZE_T str_len; // length of sequence
598
599 const char* arg; // sequence to insert
600 _RWSTD_SIZE_T arg_len; // length of sequence
601
602 const char* res; // resulting sequence
603 _RWSTD_SIZE_T nres; // length of sequence or expected result
604 // value for find, rfind, compare, etc
605
606 int bthrow; // exception expected
607};
608
609
610// describes a set of test cases for a single overload of a function
612{
613 // string function overload to exercise
615
616 // test cases to exercise overload withh
618
619 // number of test cases
620 _RWSTD_SIZE_T case_count;
621};
622
623
624// sets the {CLASS}, {FUNC}, {FUNCSIG}, and optionally {FUNCALL}
625// environment variables as follows:
626// CLASS: the name of basic_string specialization
627// FUNC: the name of the basic_string function
628// FUNCSIG: the name and signature of a specific overload
629// of the basic_string function
630// FUNCALL: a string describing the call to the basic_string function
631// with function with function arguments expanded (as specified
632// by the TestCase argument)
633_TEST_EXPORT void
634rw_setvars (const StringFunc&, const StringTestCase* = 0);
635
636typedef void StringTestFunc (const StringFunc&, const StringTestCase&);
637
638_TEST_EXPORT int
639rw_run_string_test (int, char**, const char*, const char*,
640 StringTestFunc*, const StringTest*, _RWSTD_SIZE_T);
641
642typedef void VoidFunc ();
643
644_TEST_EXPORT int
645rw_run_string_test (int, char**, const char*, const char*,
646 VoidFunc* const*, const StringTest*, _RWSTD_SIZE_T);
647
648
650template <class charT>
652{
653private:
654
655 enum { BUFSIZE = 256 };
656
657 // small buffers to avoid expensive dynamic memory allocation
658 // in most test cases (will dynamically allocate sufficient
659 // storage if necessary)
660 charT str_buf_ [BUFSIZE];
661 charT arg_buf_ [BUFSIZE];
662 charT res_buf_ [BUFSIZE];
663
664 // not defined, not copiable, not assignable
666 void operator= (const StringTestCaseData&);
667
668 // for convenience
669 typedef _RWSTD_SIZE_T SizeType;
670
671public:
672
673 SizeType strlen_; // the length of the expanded string
674 SizeType arglen_; // the length of the expanded argument
675 SizeType reslen_; // the length of the expanded result
676
677 // the offset and extent (the number of elements) of
678 // the first range into the string object being modified
679 SizeType off1_;
680 SizeType ext1_;
681
682 // the offset and extent (the number of elements) of
683 // the argument of the function call
684 SizeType off2_;
685 SizeType ext2_;
686
687 const charT* const str_; // pointer to the expanded string
688 const charT* const arg_; // pointer to the expanded argument
689 const charT* const res_; // pointer to the expanded result
690
693
694 // converts the narrow (and possibly) condensed strings to fully
695 // expanded wide character arrays that can be used to construct
696 // basic_string objects
698 : strlen_ (BUFSIZE), arglen_ (BUFSIZE), reslen_ (BUFSIZE),
699 str_ (rw_expand (str_buf_, tcase.str, tcase.str_len, &strlen_)),
700 arg_ (rw_expand (arg_buf_, tcase.arg, tcase.arg_len, &arglen_)),
701 res_ (rw_expand (res_buf_, tcase.res, tcase.nres, &reslen_)),
702 func_ (func), tcase_ (tcase) {
703 // compute the offset and extent of the string object
704 // representing the controlled sequence and the offset
705 // and extent of the argument of the function call
706 const SizeType argl = tcase_.arg ? arglen_ : strlen_;
707
708 off1_ = SizeType (tcase_.off) < strlen_ ?
709 SizeType (tcase_.off) : strlen_;
710
712 SizeType (tcase_.size) : strlen_ - off1_;
713
714 off2_ = SizeType (tcase_.off2) < argl ?
715 SizeType (tcase_.off2) : argl;
716
717 ext2_ = off2_ + tcase_.size2 < argl ?
718 SizeType (tcase_.size2) : argl - off2_;
719 }
720
722 // clean up dynamically allocated memory (if any)
723 if (str_ != str_buf_)
724 delete[] _RWSTD_CONST_CAST (charT*, str_);
725 if (arg_ != arg_buf_)
726 delete[] _RWSTD_CONST_CAST (charT*, arg_);
727 if (res_ != res_buf_)
728 delete[] _RWSTD_CONST_CAST (charT*, res_);
729 }
730};
731
732
734// encapsulates the state of a string object without regard to type
735// used in exception safety tests to determine changes to the state
736// after a modifying operation throws an exception
738{
739 const void* data_;
740 _RWSTD_SIZE_T size_;
741 _RWSTD_SIZE_T capacity_;
742
743 // invokes rw_assert() to verify that two states are the same
744 // returns 1 when the two states compare equal, and 0 otherwise
745 int assert_equal (const StringState&, int, int, const char*) const;
746};
747
748
749// creates a StringState object from a basic_string
750template <class String>
751inline StringState
753{
754 const StringState state = {
755 str.data (), str.size (), str.capacity ()
756 };
757
758 return state;
759}
760
761
762
764// base class-functor for the range template overloads testing
765template <class String>
766struct RangeBase {
767
768 typedef typename String::value_type StringChar;
769 typedef typename String::pointer StringPtr;
770 typedef typename String::const_pointer StringConstPtr;
771 typedef typename String::iterator StringIter;
772 typedef typename String::const_iterator StringConstIter;
773 typedef typename String::reverse_iterator StringRevIter;
774 typedef typename String::const_reverse_iterator StringConstRevIter;
775
777
778 virtual ~RangeBase () { /* silence warnings */ }
779
780 static StringPtr
782 return _RWSTD_CONST_CAST (StringPtr, str.data ());
783 }
784
785 static StringConstPtr
787 return str.data ();
788 }
789
790#ifndef _RWSTD_NO_DEBUG_ITER
791
792 // when debugging iterators are enabled string::iterator and
793 // string::pointer are distinct types; otherwise they are the
794 // same type
795
796 static StringIter
798 return str.begin ();
799 }
800
801 static StringConstIter
803 return str.begin ();
804 }
805
806#endif // _RWSTD_NO_DEBUG_ITER
807
808 static StringRevIter
810 return str.rbegin ();
811 }
812
813 static StringConstRevIter
815 return str.rbegin ();
816 }
817
818 virtual String&
820 RW_ASSERT (!"logic error: should be never called");
821 return str;
822 }
823};
824
825
827#define Disabled(which) \
828 StringIds::opt_memfun_disabled [which & ~StringIds::fid_mask]
829
830
831#ifndef _RWSTD_NO_WCHAR_T
832# define TEST_DISPATCH(Alloc, fname, func, tcase) \
833 if (StringIds::DefaultTraits == func.traits_id_) { \
834 if (StringIds::Char == func.char_id_) \
835 fname (char (), (std::char_traits<char>*)0, \
836 (Alloc<char>*)0, func, tcase); \
837 else if (StringIds::WChar == func.char_id_) \
838 fname (wchar_t (), (std::char_traits<wchar_t>*)0, \
839 (Alloc<wchar_t>*)0, func, tcase); \
840 else \
841 rw_note (0, 0, 0, \
842 "%{$CLASS} tests not implemented"); \
843 } \
844 else { \
845 if (StringIds::Char == func.char_id_) \
846 fname (char (), (UserTraits<char>*)0, \
847 (Alloc<char>*)0, func, tcase); \
848 else if (StringIds::WChar == func.char_id_) \
849 fname (wchar_t (), (UserTraits<wchar_t>*)0, \
850 (Alloc<wchar_t>*)0, func, tcase); \
851 else \
852 fname (UserChar (), (UserTraits<UserChar>*)0, \
853 (Alloc<UserChar>*)0, func, tcase); \
854 } \
855 (void)0
856
857#else // if defined (_RWSTD_NO_WCHAR_T)
858# define TEST_DISPATCH(Alloc, fname, func, tcase) \
859 if (StringIds::DefaultTraits == func.traits_id_) { \
860 if (StringIds::Char == func.char_id_) \
861 fname (char (), (std::char_traits<char>*)0, \
862 (Alloc<char>*)0, func, tcase); \
863 else if (StringIds::WChar == func.char_id_) \
864 RW_ASSERT (!"logic error: wchar_t disabled"); \
865 else \
866 rw_note (0, 0, 0, \
867 "%{$CLASS} tests not implemented"); \
868 } \
869 } \
870 else { \
871 if (StringIds::Char == func.char_id_) \
872 fname (char (), (UserTraits<char>*)0, \
873 (Alloc<char>*)0, func, tcase); \
874 else if (StringIds::WChar == func.char_id_) \
875 RW_ASSERT (!"logic error: wchar_t disabled"); \
876 else if (StringIds::UChar == func.char_id_) \
877 fname (UserChar (), (UserTraits<UserChar>*)0, \
878 (Alloc<UserChar>*)0, func, tcase); \
879 } \
880 (void)0
881
882#endif // _RWSTD_NO_WCHAR_T
883
884
885#define DEFINE_STRING_TEST_DISPATCH(fname) \
886 static void \
887 fname (const StringFunc &func, \
888 const StringTestCase &tcase) { \
889 if (StringIds::DefaultAlloc == func.alloc_id_) { \
890 TEST_DISPATCH (std::allocator, fname, func, tcase); \
891 } \
892 else if (StringIds::UserAlloc == func.alloc_id_) { \
893 TEST_DISPATCH (UserAlloc, fname, func, tcase); \
894 } \
895 else \
896 RW_ASSERT (!"logic error: bad allocator"); \
897 } typedef void rw_unused_typedef
898
899
900#define TFUNC(charT, Traits, Allocator) \
901 void (*)(charT*, Traits<charT>*, Allocator<charT>*, \
902 const StringTestCaseData<charT>&)
903
904#define TFUNC_ADDR(fname, charT, Traits, Allocator) \
905 (VoidFunc*)(TFUNC (charT, Traits, Allocator)) \
906 &fname<charT, Traits<charT>, Allocator<charT> >
907
908#ifndef _RWSTD_NO_WCHAR_T
909# define DEFINE_STRING_TEST_FUNCTIONS(fname) \
910 static VoidFunc* const fname ## _func_array [] = { \
911 TFUNC_ADDR (fname, char, std::char_traits, std::allocator), \
912 TFUNC_ADDR (fname, char, std::char_traits, UserAlloc), \
913 TFUNC_ADDR (fname, char, UserTraits, std::allocator), \
914 TFUNC_ADDR (fname, char, UserTraits, UserAlloc), \
915 \
916 TFUNC_ADDR (fname, wchar_t, std::char_traits, std::allocator), \
917 TFUNC_ADDR (fname, wchar_t, std::char_traits, UserAlloc), \
918 TFUNC_ADDR (fname, wchar_t, UserTraits, std::allocator), \
919 TFUNC_ADDR (fname, wchar_t, UserTraits, UserAlloc), \
920 \
921 (VoidFunc*)0, /* std::char_traits<UserChar> not allowed */ \
922 (VoidFunc*)0, /* std::char_traits<UserChar> not allowed */ \
923 TFUNC_ADDR (fname, UserChar, UserTraits, std::allocator), \
924 TFUNC_ADDR (fname, UserChar, UserTraits, UserAlloc) \
925 }
926
927#else // if defined (_RWSTD_NO_WCHAR_T)
928# define DEFINE_STRING_TEST_FUNCTIONS(fname) \
929 static VoidFunc* const fname ## _func_array [] = { \
930 TFUNC_ADDR (fname, char, std::char_traits, std::allocator), \
931 TFUNC_ADDR (fname, char, std::char_traits, UserAlloc), \
932 TFUNC_ADDR (fname, char, UserTraits, std::allocator), \
933 TFUNC_ADDR (fname, char, UserTraits, UserAlloc), \
934 \
935 (VoidFunc*)0, /* wchar_t disabled */ \
936 (VoidFunc*)0, /* wchar_t disabled */ \
937 (VoidFunc*)0, /* wchar_t disabled */ \
938 (VoidFunc*)0, /* wchar_t disabled */ \
939 \
940 (VoidFunc*)0, /* std::char_traits<UserChar> not allowed */ \
941 (VoidFunc*)0, /* std::char_traits<UserChar> not allowed */ \
942 TFUNC_ADDR (fname, UserChar, UserTraits, std::allocator), \
943 TFUNC_ADDR (fname, UserChar, UserTraits, UserAlloc) \
944 }
945
946#endif // _RWSTD_NO_WCHAR_T
947
948
949#endif // RW_21_STRINGS_H_INCLUDED
#define alloc
Definition 17.names.cpp:441
#define res
Definition 17.names.cpp:531
#define ptr
Definition 17.names.cpp:525
#define charT
Definition 17.names.cpp:456
#define val
Definition 17.names.cpp:570
const char *const data[]
#define NPOS
char * append(char *dst, const char *src)
#define _RWSTD_CONST_CAST(T, x)
Definition _defs.h:536
StringTestCaseData(const StringFunc &func, const StringTestCase &tcase)
Definition rw_strings.h:697
const StringTestCase & tcase_
Definition rw_strings.h:692
const charT *const arg_
Definition rw_strings.h:688
const charT *const res_
Definition rw_strings.h:689
const StringFunc & func_
Definition rw_strings.h:691
const charT *const str_
Definition rw_strings.h:687
const char * str
Definition exec.cpp:170
_TEST_EXPORT char * rw_expand(char *, const char *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX, _RWSTD_SIZE_T *=0)
#define NON_MEMBER_3(f, a, b, c)
Definition rw_sigdefs.h:78
_TEST_EXPORT void rw_setvars(const StringFunc &, const StringTestCase *=0)
void StringTestFunc(const StringFunc &, const StringTestCase &)
Definition rw_strings.h:636
StringState rw_get_string_state(const String &str)
Definition rw_strings.h:752
_TEST_EXPORT int rw_run_string_test(int, char **, const char *, const char *, StringTestFunc *, const StringTest *, _RWSTD_SIZE_T)
void VoidFunc()
Definition rw_strings.h:642
#define _TEST_EXPORT
Definition rw_testdefs.h:55
#define RW_ASSERT(expr)
unsigned char UChar
Definition collate.cpp:122
String::iterator StringIter
Definition rw_strings.h:771
static StringIter begin(String &str, StringIter *)
Definition rw_strings.h:797
virtual ~RangeBase()
Definition rw_strings.h:778
static StringPtr begin(String &str, StringPtr *)
Definition rw_strings.h:781
static StringConstRevIter begin(const String &str, StringConstRevIter *)
Definition rw_strings.h:814
static StringConstIter begin(const String &str, StringConstIter *)
Definition rw_strings.h:802
String::const_pointer StringConstPtr
Definition rw_strings.h:770
String::const_iterator StringConstIter
Definition rw_strings.h:772
String::reverse_iterator StringRevIter
Definition rw_strings.h:773
static StringRevIter begin(String &str, StringRevIter *)
Definition rw_strings.h:809
String::pointer StringPtr
Definition rw_strings.h:769
String::const_reverse_iterator StringConstRevIter
Definition rw_strings.h:774
String::value_type StringChar
Definition rw_strings.h:768
virtual String & operator()(String &str, const StringTestCaseData< StringChar > &) const
Definition rw_strings.h:819
static StringConstPtr begin(const String &str, StringConstPtr *)
Definition rw_strings.h:786
StringIds::TraitsId traits_id_
Definition rw_strings.h:574
StringIds::OverloadId which_
Definition rw_strings.h:577
StringIds::AllocId alloc_id_
Definition rw_strings.h:575
StringIds::CharId char_id_
Definition rw_strings.h:573
StringIds::IteratorId iter_id_
Definition rw_strings.h:576
@ fid_op_greater_equal
Definition rw_strings.h:80
@ fid_rend_const
Definition rw_strings.h:96
@ fid_find_first_not_of
Definition rw_strings.h:61
@ fid_op_less_equal
Definition rw_strings.h:78
@ fid_find_last_not_of
Definition rw_strings.h:62
@ fid_op_plus_eq
Definition rw_strings.h:56
@ fid_op_not_equal
Definition rw_strings.h:76
@ fid_find_last_of
Definition rw_strings.h:60
@ fid_op_index_const
Definition rw_strings.h:66
@ fid_op_greater
Definition rw_strings.h:79
@ fid_end_const
Definition rw_strings.h:92
@ fid_find_first_of
Definition rw_strings.h:59
@ fid_push_back
Definition rw_strings.h:73
@ fid_begin_const
Definition rw_strings.h:90
@ fid_get_allocator
Definition rw_strings.h:99
@ fid_rbegin_const
Definition rw_strings.h:94
static ArgId arg_type(OverloadId id, int argno)
Definition rw_strings.h:559
@ DefaultTraits
Definition rw_strings.h:45
_RWSTD_SIZE_T size_
Definition rw_strings.h:740
_RWSTD_SIZE_T capacity_
Definition rw_strings.h:741
const void * data_
Definition rw_strings.h:739
_RWSTD_SIZE_T arg_len
Definition rw_strings.h:600
_RWSTD_SIZE_T str_len
Definition rw_strings.h:597
const char * str
Definition rw_strings.h:596
const char * arg
Definition rw_strings.h:599
_RWSTD_SIZE_T nres
Definition rw_strings.h:603
const char * res
Definition rw_strings.h:602
const StringTestCase * cases
Definition rw_strings.h:617
StringIds::OverloadId which
Definition rw_strings.h:614
_RWSTD_SIZE_T case_count
Definition rw_strings.h:620
Helper class for suppressing move-construction in single-argument array constructors.
int arg
Definition locale.cpp:2806