4 * @brief test for STL iterator behaviour of CORBA unbounded string sequence
6 * @author Friedhelm Wolf (fwolf@dre.vanderbilt.edu)
9 #include "tao/StringSeqC.h"
10 #include "ace/Log_Msg.h"
11 #include "ace/OS_NS_string.h"
17 #define FAIL_RETURN_IF(CONDITION) \
20 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("\tFailed at %N:%l\n"))); \
24 //-----------------------------------------------------------------------------
26 #if defined TAO_HAS_SEQUENCE_ITERATORS && TAO_HAS_SEQUENCE_ITERATORS == 1
28 template <typename ITERATOR_T
>
33 // test equality operator
34 FAIL_RETURN_IF (!(a
.begin () == a
.begin ()));
36 // test non-equality operator
37 FAIL_RETURN_IF (a
.end () != a
.end ());
39 // test for correct behaviour for empty sequence
41 FAIL_RETURN_IF (a
.begin() != a
.end ());
43 // setup of an example sequence
45 const char * elem0_cstr
= "elem0";
46 const char * elem1_cstr
= "elem1";
47 const char * elem2_cstr
= "elem2";
48 const char * elem3_cstr
= "elem3";
51 // Create a case to test for memory leaks
53 a
[0] = CORBA::string_dup (elem0_cstr
);
54 a
[0] = CORBA::string_dup (elem0_cstr
);
55 a
[1] = CORBA::string_dup (elem1_cstr
);
56 a
[2] = CORBA::string_dup (elem2_cstr
);
57 a
[3] = CORBA::string_dup (elem3_cstr
);
59 // test iterator copy constructor
60 ITERATOR_T
a_it (a
.begin ());
61 FAIL_RETURN_IF (a_it
!= a
.begin ());
63 // test assignment operator
66 // Create a case to test for memory leaks
68 *a_it
= CORBA::string_dup (elem0_cstr
);
69 FAIL_RETURN_IF (a_it
!= a
.begin ());
71 // test non const dereferencing
72 // I'm not sure this test makes sense since what's returned from
73 // dereferencing the iterator is an r value.
74 const char* value_seq
= a
[0];
75 FAIL_RETURN_IF (ACE_OS::strcmp (value_seq
, elem0_cstr
) != 0);
76 const char* value0
= *a_it
;
77 FAIL_RETURN_IF (ACE_OS::strcmp (value0
, elem0_cstr
) != 0);
79 // test const dereferencing
80 const char* const value1
= *a_it
;
81 FAIL_RETURN_IF (ACE_OS::strcmp (value1
, elem0_cstr
) != 0);
83 // test increment operation
85 FAIL_RETURN_IF (a_it
== a
.begin());
86 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem1_cstr
) != 0);
89 FAIL_RETURN_IF (!(a
.begin () < a_it
));
90 FAIL_RETURN_IF (a_it
< a
.begin ());
92 // test difference type
93 int a_diff
= a_it
- a
.begin ();
94 FAIL_RETURN_IF (a_diff
!= 1);
96 // test copy constructor
97 ITERATOR_T
a_it1 (a_it
);
98 FAIL_RETURN_IF (a_it1
!= a_it
);
100 // test preincrement operator
102 FAIL_RETURN_IF ((a_it1
- a_it
) != 1);
104 // test = and += operator
105 ITERATOR_T a_it2
= a_it
+= 3;
106 FAIL_RETURN_IF (a_it2
!= a_it
);
107 FAIL_RETURN_IF ((a_it
- a_it1
) != 2);
111 FAIL_RETURN_IF ((a_it2
- a_it1
) != 3);
113 // test post-decrement operation
116 FAIL_RETURN_IF (a_it
== a
.end ());
117 FAIL_RETURN_IF ((a
.end () - a_it
) != 1);
118 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem3_cstr
) != 0);
120 // test pre-decrement operator
123 FAIL_RETURN_IF (a_it
== a
.end ());
124 FAIL_RETURN_IF ((a
.end () - a_it
) != 1);
125 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem3_cstr
) != 0);
129 FAIL_RETURN_IF ((a_it1
- a_it
) != 2);
133 FAIL_RETURN_IF ((a_it1
- a_it2
) != 2);
135 // test operator[] read
137 FAIL_RETURN_IF (ACE_OS::strcmp (a_it
[0],a
[0]) != 0);
139 FAIL_RETURN_IF (ACE_OS::strcmp (a_it
[0],a
[2]) != 0);
141 // test operator[] write
142 // NOTE: This assignment actually modifies the third element
143 // in the sequence since the iterator was previously positioned
144 // at the third element. I believe these are the proper semantics
145 // for using the bracket operator with an iterator. The number
146 // in the brackets is additive - not absolute.
147 a_it
[0] = CORBA::string_dup (elem2_cstr
);
148 FAIL_RETURN_IF (ACE_OS::strcmp (a
[2], elem2_cstr
) != 0);
150 // reset content of sequence a
151 a
[1] = CORBA::string_dup (elem1_cstr
);
153 // test for loop behaviour
154 ::CORBA::StringSeq b
= a
;
155 ITERATOR_T b_it
= b
.begin ();
157 for (a_it
= a
.begin ();
161 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, *b_it
) != 0);
164 ::CORBA::StringSeq test
;
165 test
.length (a
.length ());
167 std::copy (a
.begin (),
171 FAIL_RETURN_IF (test
.length () != a
.length ());
173 ITERATOR_T copytest_iter
= test
.begin ();
174 for (ITERATOR_T copya_iter
= a
.begin ();
175 copya_iter
!= a
.end ();
176 ++copya_iter
, ++copytest_iter
)
178 FAIL_RETURN_IF (ACE_OS::strcmp (*copya_iter
, *copytest_iter
) != 0);
181 /// Testing - using ostream_iterator
182 std::ostringstream ostream
;
183 std::copy (a
.begin (),
185 std::ostream_iterator
<CORBA::StringSeq::const_value_type
> (ostream
,
188 // The third sequence element has been modified. Either we need to restore
189 // the original sequence values or modify the test here. I modified the
190 // test since it's easier.
192 ostream
.str ().compare ("elem0\nelem1\nelem2\nelem3\n") != 0);
197 //-----------------------------------------------------------------------------
199 template <typename ITERATOR_T
>
200 int test_sequence_const_iterator ()
202 ::CORBA::StringSeq a
;
204 // test equality operator
205 FAIL_RETURN_IF (!(a
.begin () == a
.begin ()));
207 // test non-equality operator
208 FAIL_RETURN_IF (a
.end () != a
.end ());
210 // test for correct behaviour for empty sequence
212 FAIL_RETURN_IF (a
.begin() != a
.end ());
214 // setup of an example sequence
216 const char * elem0_cstr
= "elem0";
217 const char * elem1_cstr
= "elem1";
218 const char * elem2_cstr
= "elem2";
219 const char * elem3_cstr
= "elem3";
222 a
[0] = CORBA::string_dup (elem0_cstr
);
223 a
[0] = CORBA::string_dup (elem0_cstr
);
224 a
[1] = CORBA::string_dup (elem1_cstr
);
225 a
[2] = CORBA::string_dup (elem2_cstr
);
226 a
[3] = CORBA::string_dup (elem3_cstr
);
228 // test iterator copy constructor
229 ITERATOR_T
a_it (a
.begin ());
230 FAIL_RETURN_IF (a_it
!= a
.begin ());
232 // test assignment operator
234 FAIL_RETURN_IF (a_it
!= a
.begin ());
236 // test non const dereferencing
237 // I'm not sure non-const deferencing makes sense since
238 // we are getting an r value.
239 const char * value0
= *a_it
;
240 FAIL_RETURN_IF (ACE_OS::strcmp (value0
, elem0_cstr
) != 0);
242 // test const dereferencing
243 const char* const value1
= *a_it
;
244 FAIL_RETURN_IF (ACE_OS::strcmp (value1
, elem0_cstr
) != 0);
246 // test increment operation
248 FAIL_RETURN_IF (a_it
== a
.begin());
249 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem1_cstr
) != 0);
252 FAIL_RETURN_IF (!(a
.begin () < a_it
));
253 FAIL_RETURN_IF (a_it
< a
.begin ());
255 // test difference type
256 int a_diff
= a_it
- a
.begin ();
257 FAIL_RETURN_IF (a_diff
!= 1);
259 // test copy constructor
260 ITERATOR_T
a_it1 (a_it
);
261 FAIL_RETURN_IF (a_it1
!= a_it
);
263 // test preincrement operator
265 FAIL_RETURN_IF ((a_it1
- a_it
) != 1);
267 // test = and += operator
268 ITERATOR_T a_it2
= a_it
+= 3;
269 FAIL_RETURN_IF (a_it2
!= a_it
);
270 FAIL_RETURN_IF ((a_it
- a_it1
) != 2);
274 FAIL_RETURN_IF ((a_it2
- a_it1
) != 3);
276 // test post-decrement operation
279 FAIL_RETURN_IF (a_it
== a
.end ());
280 FAIL_RETURN_IF ((a
.end () - a_it
) != 1);
281 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem3_cstr
) != 0);
283 // test pre-decrement operator
286 FAIL_RETURN_IF (a_it
== a
.end ());
287 FAIL_RETURN_IF ((a
.end () - a_it
) != 1);
288 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem3_cstr
) != 0);
292 FAIL_RETURN_IF ((a_it1
- a_it
) != 2);
296 FAIL_RETURN_IF ((a_it1
- a_it2
) != 2);
298 // test operator[] read
300 FAIL_RETURN_IF (ACE_OS::strcmp (a_it
[0],a
[0]) != 0);
302 FAIL_RETURN_IF (ACE_OS::strcmp (a_it
[0],a
[2]) != 0);
304 // test for loop behaviour
305 ::CORBA::StringSeq b
= a
;
306 ITERATOR_T b_it
= b
.begin ();
308 for (a_it
= a
.begin ();
312 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, *b_it
) != 0);
315 ::CORBA::StringSeq test
;
316 test
.length (a
.length ());
318 std::copy (a
.begin (),
322 FAIL_RETURN_IF (test
.length () != a
.length ());
324 ITERATOR_T copytest_iter
= test
.begin ();
325 for (ITERATOR_T copya_iter
= a
.begin ();
326 copya_iter
!= a
.end ();
327 ++copya_iter
, ++copytest_iter
)
329 FAIL_RETURN_IF (ACE_OS::strcmp (*copya_iter
, *copytest_iter
) != 0);
332 /// Testing - using ostream_iterator
333 std::ostringstream ostream
;
334 std::copy (a
.begin (),
336 std::ostream_iterator
<CORBA::StringSeq::const_value_type
>(ostream
,
340 ostream
.str ().compare ("elem0\nelem1\nelem2\nelem3\n") != 0);
345 //-----------------------------------------------------------------------------
347 template <typename ITERATOR_T
>
348 int test_const_sequence ()
350 // setup of an example sequence
351 const char * elem0_cstr
= "elem0";
352 const char * elem1_cstr
= "elem1";
353 const char * elem2_cstr
= "elem2";
354 const char * elem3_cstr
= "elem3";
356 ::CORBA::StringSeq setup
;
358 setup
[0] = CORBA::string_dup (elem0_cstr
);
359 setup
[1] = CORBA::string_dup (elem1_cstr
);
360 setup
[2] = CORBA::string_dup (elem2_cstr
);
361 setup
[3] = CORBA::string_dup (elem3_cstr
);
363 const ::CORBA::StringSeq a
= setup
;
365 // test equality operator
366 FAIL_RETURN_IF (!(a
.begin () == a
.begin ()));
367 ITERATOR_T
c_iter1 (a
.begin ());
368 ITERATOR_T c_iter2
= a
.begin ();
369 FAIL_RETURN_IF (!(c_iter1
== c_iter2
));
371 // test non-equality operator
372 FAIL_RETURN_IF (a
.end () != a
.end ());
374 // test iterator copy constructor
375 ITERATOR_T
a_it (a
.begin ());
376 FAIL_RETURN_IF (a_it
!= a
.begin ());
378 // test non const dereferencing
379 // JWH2 - This test shouldn't be done when dealing with
380 // a const iterator (which we sometimes do with the current
382 //typename ITERATOR_T::element_type value0 = *a_it;
383 //FAIL_RETURN_IF (ACE_OS::strcmp (value0, elem0_cstr) != 0);
385 // test const dereferencing
386 typename
ITERATOR_T::const_element_type value1
= *a_it
;
387 FAIL_RETURN_IF (ACE_OS::strcmp (value1
, elem0_cstr
) != 0);
389 // test increment operation
391 FAIL_RETURN_IF (a_it
== a
.begin());
392 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem1_cstr
) != 0);
395 FAIL_RETURN_IF (!(a
.begin () < a_it
));
396 FAIL_RETURN_IF (a_it
< a
.begin ());
398 // test difference type
399 int a_diff
= a_it
- a
.begin ();
400 FAIL_RETURN_IF (a_diff
!= 1);
402 // test copy constructor
403 ITERATOR_T
a_it1 (a_it
);
404 FAIL_RETURN_IF (a_it1
!= a_it
);
406 // test preincrement operator
408 FAIL_RETURN_IF ((a_it1
- a_it
) != 1);
410 // test = and += operator
411 ITERATOR_T a_it2
= a_it
+= 3;
412 FAIL_RETURN_IF (a_it2
!= a_it
);
413 FAIL_RETURN_IF ((a_it
- a_it1
) != 2);
417 FAIL_RETURN_IF ((a_it2
- a_it1
) != 3);
419 // test post-decrement operation
422 FAIL_RETURN_IF (a_it
== a
.end ());
423 FAIL_RETURN_IF ((a
.end () - a_it
) != 1);
424 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem3_cstr
) != 0);
426 // test pre-decrement operator
429 FAIL_RETURN_IF (a_it
== a
.end ());
430 FAIL_RETURN_IF ((a
.end () - a_it
) != 1);
431 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem3_cstr
) != 0);
435 FAIL_RETURN_IF ((a_it1
- a_it
) != 2);
439 FAIL_RETURN_IF ((a_it1
- a_it2
) != 2);
441 // test operator[] read
443 FAIL_RETURN_IF (ACE_OS::strcmp (a_it
[0],a
[0]) != 0);
445 FAIL_RETURN_IF (ACE_OS::strcmp (a_it
[0],a
[2]) != 0);
447 // test for loop behaviour
448 const ::CORBA::StringSeq b
= a
;
449 ITERATOR_T b_it
= b
.begin ();
451 for (a_it
= a
.begin ();
455 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, *b_it
) != 0);
458 ::CORBA::StringSeq test
;
459 test
.length (a
.length ());
461 std::copy (a
.begin (),
465 FAIL_RETURN_IF (test
.length () != a
.length ());
467 ITERATOR_T copytest_iter
= test
.begin ();
468 for (ITERATOR_T copya_iter
= a
.begin ();
469 copya_iter
!= a
.end ();
470 ++copya_iter
, ++copytest_iter
)
472 FAIL_RETURN_IF (ACE_OS::strcmp (*copya_iter
, *copytest_iter
) != 0);
475 /// Testing - using ostream_iterator
476 std::ostringstream ostream
;
477 std::copy (a
.begin (),
479 std::ostream_iterator
<CORBA::StringSeq::const_value_type
> (ostream
,
483 ostream
.str ().compare ("elem0\nelem1\nelem2\nelem3\n") != 0);
488 //-----------------------------------------------------------------------------
490 template <typename REVERSE_ITERATOR_T
>
491 int test_sequence_reverse ()
493 ::CORBA::StringSeq a
;
495 // test equality operator
496 FAIL_RETURN_IF (!(a
.begin () == a
.begin ()));
498 // test non-equality operator
499 FAIL_RETURN_IF (a
.end () != a
.end ());
501 // test for correct behaviour for empty sequence
503 FAIL_RETURN_IF (a
.begin() != a
.end ());
505 // setup of an example sequence
506 const char * elem0_cstr
= "elem0";
507 const char * elem1_cstr
= "elem1";
508 const char * elem2_cstr
= "elem2";
509 const char * elem3_cstr
= "elem3";
512 a
[0] = CORBA::string_dup (elem0_cstr
);
513 a
[1] = CORBA::string_dup (elem1_cstr
);
514 a
[2] = CORBA::string_dup (elem2_cstr
);
515 a
[3] = CORBA::string_dup (elem3_cstr
);
517 // test iterator copy constructor
518 REVERSE_ITERATOR_T
a_it (a
.rbegin ());
519 FAIL_RETURN_IF (a_it
!= a
.rbegin ());
521 // test assignment operator
524 // Create a case to test for memory leaks
526 *a_it
= CORBA::string_dup (elem3_cstr
);
527 FAIL_RETURN_IF (a_it
!= a
.rbegin ());
529 // test non const dereferencing
530 typename
REVERSE_ITERATOR_T::element_type value0
= *a_it
;
531 FAIL_RETURN_IF (ACE_OS::strcmp (value0
, elem3_cstr
) != 0);
533 // test const dereferencing
534 const char* const value1
= *a_it
;
535 FAIL_RETURN_IF (ACE_OS::strcmp (value1
, elem3_cstr
) != 0);
537 // test increment operation
539 FAIL_RETURN_IF (a_it
== a
.rbegin());
540 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem2_cstr
) != 0);
543 FAIL_RETURN_IF (!(a
.rbegin () < a_it
));
544 FAIL_RETURN_IF (a_it
< a
.rbegin ());
546 // test difference type
547 int a_diff
= a_it
- a
.rbegin ();
548 FAIL_RETURN_IF (a_diff
!= 1);
550 // test copy constructor
551 REVERSE_ITERATOR_T
a_it1 (a_it
);
552 FAIL_RETURN_IF (a_it1
!= a_it
);
554 // test preincrement operator
556 FAIL_RETURN_IF ((a_it1
- a_it
) != 1);
558 // test = and += operator
559 REVERSE_ITERATOR_T a_it2
= a_it
+= 3;
560 FAIL_RETURN_IF (a_it2
!= a_it
);
561 FAIL_RETURN_IF ((a_it
- a_it1
) != 2);
565 FAIL_RETURN_IF ((a_it2
- a_it1
) != 3);
567 // test post-decrement operation
570 FAIL_RETURN_IF (a_it
== a
.rend ());
571 FAIL_RETURN_IF ((a
.rend () - a_it
) != 1);
572 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem0_cstr
) != 0);
574 // test pre-decrement operator
577 FAIL_RETURN_IF (a_it
== a
.rend ());
578 FAIL_RETURN_IF ((a
.rend () - a_it
) != 1);
579 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem0_cstr
) != 0);
583 FAIL_RETURN_IF ((a_it1
- a_it
) != 2);
587 FAIL_RETURN_IF ((a_it1
- a_it2
) != 2);
589 // test operator[] read
591 FAIL_RETURN_IF (ACE_OS::strcmp (a_it
[0],a
[3]) != 0);
593 FAIL_RETURN_IF (ACE_OS::strcmp (a_it
[0],a
[1]) != 0);
595 // test operator[] write
596 a_it
[0] = CORBA::string_dup (elem0_cstr
);
597 FAIL_RETURN_IF (ACE_OS::strcmp (a
[1],elem0_cstr
) != 0);
599 // reset content of sequence a
600 a
[1] = CORBA::string_dup (elem1_cstr
);
602 // test for loop behaviour
603 ::CORBA::StringSeq b
= a
;
604 REVERSE_ITERATOR_T b_it
= b
.rbegin ();
606 for (a_it
= a
.rbegin ();
610 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, *b_it
) != 0);
613 ::CORBA::StringSeq test
;
614 test
.length (a
.length ());
616 std::copy (a
.begin (),
620 FAIL_RETURN_IF (test
.length () != a
.length ());
622 REVERSE_ITERATOR_T copytest_iter
= test
.rbegin ();
623 for (REVERSE_ITERATOR_T copya_iter
= a
.rbegin ();
624 copya_iter
!= a
.rend ();
625 ++copya_iter
, ++copytest_iter
)
627 FAIL_RETURN_IF (ACE_OS::strcmp (*copya_iter
, *copytest_iter
) != 0);
630 /// Testing - using ostream_iterator
631 std::ostringstream ostream
;
632 std::copy (a
.rbegin (),
634 std::ostream_iterator
<CORBA::StringSeq::element_type
> (ostream
,
638 ostream
.str ().compare ("elem3\nelem2\nelem1\nelem0\n") != 0);
643 //-----------------------------------------------------------------------------
645 template <typename REVERSE_ITERATOR_T
>
646 int test_sequence_reverse_const_iterator ()
648 ::CORBA::StringSeq a
;
650 // test equality operator
651 FAIL_RETURN_IF (!(a
.begin () == a
.begin ()));
653 // test non-equality operator
654 FAIL_RETURN_IF (a
.end () != a
.end ());
656 // test for correct behaviour for empty sequence
658 FAIL_RETURN_IF (a
.begin() != a
.end ());
660 // setup of an example sequence
661 const char * elem0_cstr
= "elem0";
662 const char * elem1_cstr
= "elem1";
663 const char * elem2_cstr
= "elem2";
664 const char * elem3_cstr
= "elem3";
667 a
[0] = CORBA::string_dup (elem0_cstr
);
668 a
[1] = CORBA::string_dup (elem1_cstr
);
669 a
[2] = CORBA::string_dup (elem2_cstr
);
670 a
[3] = CORBA::string_dup (elem3_cstr
);
672 // test iterator copy constructor
673 REVERSE_ITERATOR_T
a_it (a
.rbegin ());
674 FAIL_RETURN_IF (a_it
!= a
.rbegin ());
676 // test assignment operator
678 FAIL_RETURN_IF (a_it
!= a
.rbegin ());
680 // test non const dereferencing
681 typename
REVERSE_ITERATOR_T::const_element_type value0
= *a_it
;
682 FAIL_RETURN_IF (ACE_OS::strcmp (value0
, elem3_cstr
) != 0);
684 // test const dereferencing
685 const char* const value1
= *a_it
;
686 FAIL_RETURN_IF (ACE_OS::strcmp (value1
, elem3_cstr
) != 0);
688 // test increment operation
690 FAIL_RETURN_IF (a_it
== a
.rbegin());
691 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem2_cstr
) != 0);
694 FAIL_RETURN_IF (!(a
.rbegin () < a_it
));
695 FAIL_RETURN_IF (a_it
< a
.rbegin ());
697 // test difference type
698 int a_diff
= a_it
- a
.rbegin ();
699 FAIL_RETURN_IF (a_diff
!= 1);
701 // test copy constructor
702 REVERSE_ITERATOR_T
a_it1 (a_it
);
703 FAIL_RETURN_IF (a_it1
!= a_it
);
705 // test preincrement operator
707 FAIL_RETURN_IF ((a_it1
- a_it
) != 1);
709 // test = and += operator
710 REVERSE_ITERATOR_T a_it2
= a_it
+= 3;
711 FAIL_RETURN_IF (a_it2
!= a_it
);
712 FAIL_RETURN_IF ((a_it
- a_it1
) != 2);
716 FAIL_RETURN_IF ((a_it2
- a_it1
) != 3);
718 // test post-decrement operation
721 FAIL_RETURN_IF (a_it
== a
.rend ());
722 FAIL_RETURN_IF ((a
.rend () - a_it
) != 1);
723 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem0_cstr
) != 0);
725 // test pre-decrement operator
728 FAIL_RETURN_IF (a_it
== a
.rend ());
729 FAIL_RETURN_IF ((a
.rend () - a_it
) != 1);
730 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem0_cstr
) != 0);
734 FAIL_RETURN_IF ((a_it1
- a_it
) != 2);
738 FAIL_RETURN_IF ((a_it1
- a_it2
) != 2);
740 // test operator[] read
742 FAIL_RETURN_IF (ACE_OS::strcmp (a_it
[0],a
[3]) != 0);
744 FAIL_RETURN_IF (ACE_OS::strcmp (a_it
[0],a
[1]) != 0);
746 // test for loop behaviour
747 ::CORBA::StringSeq b
= a
;
748 REVERSE_ITERATOR_T b_it
= b
.rbegin ();
750 for (a_it
= a
.rbegin ();
754 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, *b_it
) != 0);
757 ::CORBA::StringSeq test
;
758 test
.length (a
.length ());
760 std::copy (a
.begin (),
764 FAIL_RETURN_IF (test
.length () != a
.length ());
766 REVERSE_ITERATOR_T copytest_iter
= test
.rbegin ();
767 for (REVERSE_ITERATOR_T copya_iter
= a
.rbegin ();
768 copya_iter
!= a
.rend ();
769 ++copya_iter
, ++copytest_iter
)
771 FAIL_RETURN_IF (ACE_OS::strcmp (*copya_iter
, *copytest_iter
) != 0);
774 /// Testing - using ostream_iterator
775 std::ostringstream ostream
;
776 std::copy (a
.rbegin (),
778 std::ostream_iterator
<CORBA::StringSeq::element_type
> (ostream
,
782 ostream
.str ().compare ("elem3\nelem2\nelem1\nelem0\n") != 0);
787 //-----------------------------------------------------------------------------
789 template <typename REVERSE_ITERATOR_T
>
790 int test_const_sequence_reverse ()
792 // setup of an example sequence
793 const char * elem0_cstr
= "elem0";
794 const char * elem1_cstr
= "elem1";
795 const char * elem2_cstr
= "elem2";
796 const char * elem3_cstr
= "elem3";
798 ::CORBA::StringSeq setup
;;
800 setup
[0] = CORBA::string_dup (elem0_cstr
);
801 setup
[1] = CORBA::string_dup (elem1_cstr
);
802 setup
[2] = CORBA::string_dup (elem2_cstr
);
803 setup
[3] = CORBA::string_dup (elem3_cstr
);
805 const ::CORBA::StringSeq a
= setup
;
807 // test equality operator
808 FAIL_RETURN_IF (!(a
.begin () == a
.begin ()));
810 // test non-equality operator
811 FAIL_RETURN_IF (a
.end () != a
.end ());
813 // test iterator copy constructor
814 REVERSE_ITERATOR_T
a_it (a
.rbegin ());
815 FAIL_RETURN_IF (a_it
!= a
.rbegin ());
817 // test non const dereferencing
818 typename
REVERSE_ITERATOR_T::const_element_type value0
= *a_it
;
819 FAIL_RETURN_IF (ACE_OS::strcmp (value0
, elem3_cstr
) != 0);
821 // test const dereferencing
822 const char* const value1
= *a_it
;
823 FAIL_RETURN_IF (ACE_OS::strcmp (value1
, elem3_cstr
) != 0);
825 // test increment operation
827 FAIL_RETURN_IF (a_it
== a
.rbegin());
828 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem2_cstr
) != 0);
831 FAIL_RETURN_IF (!(a
.rbegin () < a_it
));
832 FAIL_RETURN_IF (a_it
< a
.rbegin ());
834 // test difference type
835 int a_diff
= a_it
- a
.rbegin ();
836 FAIL_RETURN_IF (a_diff
!= 1);
838 // test copy constructor
839 REVERSE_ITERATOR_T
a_it1 (a_it
);
840 FAIL_RETURN_IF (a_it1
!= a_it
);
842 // test preincrement operator
844 FAIL_RETURN_IF ((a_it1
- a_it
) != 1);
846 // test = and += operator
847 REVERSE_ITERATOR_T a_it2
= a_it
+= 3;
848 FAIL_RETURN_IF (a_it2
!= a_it
);
849 FAIL_RETURN_IF ((a_it
- a_it1
) != 2);
853 FAIL_RETURN_IF ((a_it2
- a_it1
) != 3);
855 // test post-decrement operation
858 FAIL_RETURN_IF (a_it
== a
.rend ());
859 FAIL_RETURN_IF ((a
.rend () - a_it
) != 1);
860 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem0_cstr
) != 0);
862 // test pre-decrement operator
865 FAIL_RETURN_IF (a_it
== a
.rend ());
866 FAIL_RETURN_IF ((a
.rend () - a_it
) != 1);
867 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, elem0_cstr
) != 0);
871 FAIL_RETURN_IF ((a_it1
- a_it
) != 2);
875 FAIL_RETURN_IF ((a_it1
- a_it2
) != 2);
877 // test operator[] read
879 FAIL_RETURN_IF (ACE_OS::strcmp (a_it
[0],a
[3]) != 0);
881 FAIL_RETURN_IF (ACE_OS::strcmp (a_it
[0],a
[1]) != 0);
883 // test for loop behaviour
884 ::CORBA::StringSeq b
= a
;
885 REVERSE_ITERATOR_T b_it
= b
.rbegin ();
887 for (a_it
= a
.rbegin ();
891 FAIL_RETURN_IF (ACE_OS::strcmp (*a_it
, *b_it
) != 0);
894 ::CORBA::StringSeq test
;
895 test
.length (a
.length ());
897 std::copy (a
.begin (),
901 FAIL_RETURN_IF (test
.length () != a
.length ());
903 REVERSE_ITERATOR_T copytest_iter
= test
.rbegin ();
904 for (REVERSE_ITERATOR_T copya_iter
= a
.rbegin ();
905 copya_iter
!= a
.rend ();
906 ++copya_iter
, ++copytest_iter
)
908 FAIL_RETURN_IF (ACE_OS::strcmp (*copya_iter
, *copytest_iter
) != 0);
911 /// Testing - using ostream_iterator
912 std::ostringstream ostream
;
913 std::copy (a
.rbegin (),
915 std::ostream_iterator
<CORBA::StringSeq::const_element_type
> (ostream
,
919 ostream
.str ().compare ("elem3\nelem2\nelem1\nelem0\n") != 0);
926 //-----------------------------------------------------------------------------
928 int ACE_TMAIN(int,ACE_TCHAR
*[])
932 #if defined TAO_HAS_SEQUENCE_ITERATORS && TAO_HAS_SEQUENCE_ITERATORS == 1
934 // Test Generic_Sequence_Iterator.
935 status
+= test_sequence
< ::CORBA::StringSeq::iterator
> ();
937 // g++ seems to make the conversion from iterator to const_iterator
938 // and Windows doesn't. Not sure why.
939 // Test Const_Generic_Sequence_Iterator with non-const sequence.
940 status
+= test_sequence_const_iterator
<
941 ::CORBA::StringSeq::const_iterator
> ();
943 // Test Const_Generic_Sequence_Iterator with const sequence.
944 status
+= test_const_sequence
< ::CORBA::StringSeq::const_iterator
> ();
946 // Test Generic_Sequence_Reverse_Iterator.
947 status
+= test_sequence_reverse
< ::CORBA::StringSeq::reverse_iterator
> ();
949 // Test Const_Generic_Sequence_Reverse_Iterator with non-const sequence.
950 status
+= test_sequence_reverse_const_iterator
<
951 ::CORBA::StringSeq::const_reverse_iterator
> ();
953 // Test Const_Generic_Sequence_Reverse_Iterator with const sequence.
954 status
+= test_const_sequence_reverse
<
955 ::CORBA::StringSeq::const_reverse_iterator
> ();