From 9feb8ea5e2d5845da0cdb0fc92ba81a38712a90a Mon Sep 17 00:00:00 2001 From: wolff1 Date: Fri, 21 Dec 2007 19:11:22 +0000 Subject: added initial Unbounded_Object_Ref_Sequence test and checks for ACE_HAS_STDCPP_STL_INCLUDES --- TAO/tao/Bounded_Basic_String_Sequence_T.h | 4 + TAO/tao/Generic_Sequence_T.h | 15 ++ TAO/tao/Unbounded_Basic_String_Sequence_T.h | 3 + TAO/tao/Unbounded_Object_Reference_Sequence_T.h | 64 +++++++ TAO/tao/Unbounded_Value_Sequence_T.h | 8 +- .../Sequence_Iterators/Sequence_Iterators.mpc | 16 ++ .../Sequence_Iterators/Unbounded_Objectref.cpp | 185 +++++++++++++++++++++ TAO/tests/Sequence_Iterators/run_test.pl | 10 +- 8 files changed, 296 insertions(+), 9 deletions(-) create mode 100644 TAO/tests/Sequence_Iterators/Unbounded_Objectref.cpp diff --git a/TAO/tao/Bounded_Basic_String_Sequence_T.h b/TAO/tao/Bounded_Basic_String_Sequence_T.h index 7a3f5e1cd28..923447e523b 100644 --- a/TAO/tao/Bounded_Basic_String_Sequence_T.h +++ b/TAO/tao/Bounded_Basic_String_Sequence_T.h @@ -105,6 +105,8 @@ public: implementation_type::freebuf(buffer); } +#ifdef ACE_HAS_STDCPP_STL_INCLUDES + /// /// Additions to support iterator semantics for TAO unbounded basic /// string sequences. @@ -166,6 +168,8 @@ public: return impl_.rend (); } +#endif /* ACE_HAS_STDCPP_STL_INCLUDES */ + private: implementation_type impl_; }; diff --git a/TAO/tao/Generic_Sequence_T.h b/TAO/tao/Generic_Sequence_T.h index 8ea9e4869d7..1fd067c4c83 100644 --- a/TAO/tao/Generic_Sequence_T.h +++ b/TAO/tao/Generic_Sequence_T.h @@ -68,6 +68,8 @@ namespace TAO namespace details { +#ifdef ACE_HAS_STDCPP_STL_INCLUDES + // Forward declare the iterators template class Generic_Sequence_Iterator; @@ -81,16 +83,23 @@ class Generic_Sequence_Reverse_Iterator; template class Const_Generic_Sequence_Reverse_Iterator; +#endif /* ACE_HAS_STDCPP_STL_INCLUDES */ + template class generic_sequence { + +#ifdef ACE_HAS_STDCPP_STL_INCLUDES + friend class Generic_Sequence_Iterator >; friend class Const_Generic_Sequence_Iterator >; friend class Generic_Sequence_Reverse_Iterator >; friend class Const_Generic_Sequence_Reverse_Iterator >; +#endif /* ACE_HAS_STDCPP_STL_INCLUDES */ + public: typedef T value_type; typedef ALLOCATION_TRAITS allocation_traits; @@ -335,6 +344,8 @@ public: allocation_traits::freebuf(buffer); } +#ifdef ACE_HAS_STDCPP_STL_INCLUDES + /// /// Additions to support iterator semantics for TAO sequences. /// @@ -405,6 +416,8 @@ public: -1); } +#endif /* ACE_HAS_STDCPP_STL_INCLUDES */ + private: /// The maximum number of elements the buffer can contain. CORBA::ULong maximum_; @@ -417,6 +430,7 @@ private: mutable CORBA::Boolean release_; }; +#ifdef ACE_HAS_STDCPP_STL_INCLUDES /** * @class Generic_Sequence_Iterator @@ -1294,6 +1308,7 @@ template return Const_Generic_Sequence_Reverse_Iterator (iter.sequence_, iter.pos_ + n); } +#endif /* ACE_HAS_STDCPP_STL_INCLUDES */ } // namespace details } // namespace TAO diff --git a/TAO/tao/Unbounded_Basic_String_Sequence_T.h b/TAO/tao/Unbounded_Basic_String_Sequence_T.h index b4d419cc573..9c0194a86d5 100644 --- a/TAO/tao/Unbounded_Basic_String_Sequence_T.h +++ b/TAO/tao/Unbounded_Basic_String_Sequence_T.h @@ -112,6 +112,7 @@ public: implementation_type::freebuf(buffer); } +#ifdef ACE_HAS_STDCPP_STL_INCLUDES /// /// Additions to support iterator semantics for TAO unbounded basic @@ -174,6 +175,8 @@ public: return impl_.rend (); } +#endif /* ACE_HAS_STDCPP_STL_INCLUDES */ + private: implementation_type impl_; }; diff --git a/TAO/tao/Unbounded_Object_Reference_Sequence_T.h b/TAO/tao/Unbounded_Object_Reference_Sequence_T.h index 50d1ae9fd9b..3bfc59f384c 100644 --- a/TAO/tao/Unbounded_Object_Reference_Sequence_T.h +++ b/TAO/tao/Unbounded_Object_Reference_Sequence_T.h @@ -107,6 +107,70 @@ public: implementation_type::freebuf(buffer); } +#ifdef ACE_HAS_STDCPP_STL_INCLUDES + + /// + /// Additions to support iterator semantics for TAO unbounded object reference + /// sequences. + /// + + // = Traits and factory methods that create iterators. + typedef details::Generic_Sequence_Iterator > iterator; + typedef details::Const_Generic_Sequence_Iterator > const_iterator; + typedef details::Generic_Sequence_Reverse_Iterator > reverse_iterator; + typedef details::Const_Generic_Sequence_Reverse_Iterator > const_reverse_iterator; + + // Get an iterator that points to the beginning of the sequence. + iterator begin (void) + { + return impl_.begin (); + } + + // Get a const iterator that points to the beginning of the sequence. + const_iterator begin (void) const + { + return impl_.begin (); + } + + // Get an iterator that points to the end of the sequence. + iterator end (void) + { + return impl_.end (); + } + + // Get a const iterator that points to the end of the sequence. + const_iterator end (void) const + { + return impl_.end (); + } + + // Get a reverse iterator that points to the end of the sequence. + reverse_iterator rbegin (void) + { + return impl_.rbegin (); + } + + // Get a const reverse iterator that points to the end of the sequence. + const_reverse_iterator rbegin (void) const + { + return impl_.rbegin (); + } + + // Get a reverse iterator that points to one before the beginning + // of the sequence. + reverse_iterator rend (void) + { + return impl_.end (); + } + + // Get a const reverse iterator that points to one before the + // beginning of the sequence. + const_reverse_iterator rend (void) const + { + return impl_.rend (); + } + +#endif /* ACE_HAS_STDCPP_STL_INCLUDES */ private: implementation_type impl_; diff --git a/TAO/tao/Unbounded_Value_Sequence_T.h b/TAO/tao/Unbounded_Value_Sequence_T.h index 742324745c1..ab72d60c3c1 100644 --- a/TAO/tao/Unbounded_Value_Sequence_T.h +++ b/TAO/tao/Unbounded_Value_Sequence_T.h @@ -89,9 +89,11 @@ public: implementation_type::freebuf(buffer); } +#ifdef ACE_HAS_STDCPP_STL_INCLUDES + /// - /// Additions to support iterator semantics for TAO unbounded basic - /// string sequences. + /// Additions to support iterator semantics for TAO unbounded value + /// sequences. /// // = Traits and factory methods that create iterators. @@ -150,6 +152,8 @@ public: return impl_.rend (); } +#endif /* ACE_HAS_STDCPP_STL_INCLUDES */ + private: implementation_type impl_; }; diff --git a/TAO/tests/Sequence_Iterators/Sequence_Iterators.mpc b/TAO/tests/Sequence_Iterators/Sequence_Iterators.mpc index f07b9c6cd82..31f3f0e886f 100644 --- a/TAO/tests/Sequence_Iterators/Sequence_Iterators.mpc +++ b/TAO/tests/Sequence_Iterators/Sequence_Iterators.mpc @@ -2,13 +2,29 @@ // $Id$ project(StringSeq) : taoexe { + + exename = StringSeq + Source_Files { StringSeq.cpp } } project(Bounded_String) : taoexe { + + exename = Bounded_String + Source_Files { Bounded_String.cpp } +} + +project(Unbounded_Objectref) : taoexe { + + exename = Unbounded_Objectref + + Source_Files { + mock_reference.cpp + Unbounded_Objectref.cpp + } } \ No newline at end of file diff --git a/TAO/tests/Sequence_Iterators/Unbounded_Objectref.cpp b/TAO/tests/Sequence_Iterators/Unbounded_Objectref.cpp new file mode 100644 index 00000000000..418d2cb2bb9 --- /dev/null +++ b/TAO/tests/Sequence_Iterators/Unbounded_Objectref.cpp @@ -0,0 +1,185 @@ +/** + * @file Unbounded_Objectref.cpp + * + * @brief test for STL iterator behaviour of CORBA unbounded value sequence + * + * $Id$ + * + * @author Friedhelm Wolf (fwolf@dre.vanderbilt.edu) + */ + +#include "ace/Log_Msg.h" + +#include +#include +#include + +#include "tao/Object_Reference_Traits_T.h" +#include "mock_reference.hpp" +#include "tao/Unbounded_Object_Reference_Sequence_T.h" + +#define FAIL_RETURN_IF(CONDITION) \ + ACE_DEBUG ((LM_INFO, ACE_TEXT ("in %N:%l\n"))); \ + if (CONDITION) \ + { \ + ACE_DEBUG ((LM_ERROR, ACE_TEXT ("\tFailed at %N:%l\n"))); \ + return 1; \ + } + +typedef TAO::unbounded_object_reference_sequence tested_sequence; + +template +int test_sequence () +{ + tested_sequence a; + + // test equality operator + FAIL_RETURN_IF (!(a.begin () == a.begin ())); + + // test non-equality operator + FAIL_RETURN_IF (a.end () != a.end ()); + + // test for correct behaviour for empty sequence + + FAIL_RETURN_IF (a.begin() != a.end ()); + + mock_reference* elem0 = mock_reference::allocate (0); + mock_reference* elem1 = mock_reference::allocate (1); + mock_reference* elem2 = mock_reference::allocate (2); + mock_reference* elem3 = mock_reference::allocate (3); + + // setup of an example sequence + a.length (4); + a[0] = mock_reference::_duplicate (elem0); + a[1] = mock_reference::_duplicate (elem1); + a[2] = mock_reference::_duplicate (elem2); + a[3] = mock_reference::_duplicate (elem3); + + // test iterator copy constructor + ITERATOR_T a_it (a.begin ()); + FAIL_RETURN_IF (a_it != a.begin ()); + + // test assignment operator + a_it = a.begin (); + FAIL_RETURN_IF (a_it != a.begin ()); + + // test non const dereferencing + mock_reference* value0 = *a_it; + FAIL_RETURN_IF (value0->id () != elem0->id ()); + + // test const dereferencing + const mock_reference* const value1 = *a_it; + FAIL_RETURN_IF (value1->id () != elem0->id ()); + + // test increment operation + a_it++; + FAIL_RETURN_IF (a_it == a.begin()); + FAIL_RETURN_IF ((*a_it)->id () != elem1->id ()); + + // test < operator + FAIL_RETURN_IF (!(a.begin () < a_it)); + FAIL_RETURN_IF (a_it < a.begin ()); + + // test difference type + int a_diff = a_it - a.begin (); + FAIL_RETURN_IF (a_diff != 1); + + // test copy constructor + ITERATOR_T a_it1 (a_it); + FAIL_RETURN_IF (a_it1 != a_it); + + // test preincrement operator + ++a_it1; + FAIL_RETURN_IF ((a_it1 - a_it) != 1); + + // test = and += operator + ITERATOR_T a_it2 = a_it += 3; + FAIL_RETURN_IF (a_it2 != a_it); + FAIL_RETURN_IF ((a_it - a_it1) != 2); + + // test + operator + a_it2 = a_it1 + 3; + FAIL_RETURN_IF ((a_it2 - a_it1) != 3); + + // test post-decrement operation + a_it = a.end (); + a_it--; + FAIL_RETURN_IF (a_it == a.end ()); + FAIL_RETURN_IF ((a.end () - a_it) != 1); + FAIL_RETURN_IF ((*a_it)->id () != elem3->id ()); + + // test pre-decrement operator + a_it = a.end (); + --a_it; + FAIL_RETURN_IF (a_it == a.end ()); + FAIL_RETURN_IF ((a.end () - a_it) != 1); + FAIL_RETURN_IF ((*a_it)->id () != elem3->id ()); + + // test -= operator + a_it -= 3; + FAIL_RETURN_IF ((a_it1 - a_it) != 2); + + // test - operator + a_it2 = a_it1 - 2; + FAIL_RETURN_IF ((a_it1 - a_it2) != 2); + + // test operator[] read + a_it = a.begin (); + FAIL_RETURN_IF (a_it[0]->id () != a[0]->id ()); + a_it += 2; + FAIL_RETURN_IF (a_it[0]->id () != a[2]->id ()); + + // test for loop behaviour + tested_sequence b = a; + ITERATOR_T b_it = b.begin (); + + for (a_it = a.begin (); + a_it != a.end (); + a_it++, b_it++) + { + FAIL_RETURN_IF ((*a_it)->id () != (*b_it)->id ()); + } + + tested_sequence test; + test.length (a.length ()); + + // Memory is leaked here from + // TAO::details::string_traits_base::default_initializer() + + std::copy (a.begin (), + a.end (), + test.begin ()); + + FAIL_RETURN_IF (test.length () != a.length ()); + + ITERATOR_T copytest_iter = test.begin (); + for (ITERATOR_T copya_iter = a.begin (); + copya_iter != a.end (); + ++copya_iter, ++copytest_iter) + { + FAIL_RETURN_IF ((*copya_iter)->id () != (*copytest_iter)->id ()); + } + + /// Testing - using ostream_iterator + + std::ostringstream ostream; + std::copy (a.begin (), + a.end (), + std::ostream_iterator (ostream, + "\n")); + + FAIL_RETURN_IF ( + ostream.str ().compare ("elem0\nelem1\nelem2\nelem3\n") != 0); + + return 0; +} + +int main(int,char*[]) +{ + int status = 0; + + // Test Generic_Sequence_Iterator. + status += test_sequence< tested_sequence::iterator> (); + + return status; +} diff --git a/TAO/tests/Sequence_Iterators/run_test.pl b/TAO/tests/Sequence_Iterators/run_test.pl index 7bfb5ce867a..6dc14ab3f2c 100755 --- a/TAO/tests/Sequence_Iterators/run_test.pl +++ b/TAO/tests/Sequence_Iterators/run_test.pl @@ -38,11 +38,9 @@ my @tests = qw( ); my @testsNoBoost = qw( -# Unbounded_Octet -# Unbounded_Simple_Types -# Bounded_Simple_Types - StringSeq - Bounded_String + StringSeq + Bounded_String + Unbounded_Objectref ); my @testsToRun = qw(); @@ -53,8 +51,6 @@ push(@testsToRun, @testsNoBoost) if ($#ARGV < 0 || $ARGV[0] eq '-noboost'); foreach my $process (@testsToRun) { - - my $P = 0; if (PerlACE::is_vxworks_test()) { $P = new PerlACE::ProcessVX ($process, -- cgit v1.2.1