|
Boost-Commit : |
From: nesotto_at_[hidden]
Date: 2007-10-25 16:49:03
Author: nesotto
Date: 2007-10-25 16:49:02 EDT (Thu, 25 Oct 2007)
New Revision: 40465
URL: http://svn.boost.org/trac/boost/changeset/40465
Log:
major update of test to handle new functionality and better test of old functionality
Text files modified:
trunk/libs/ptr_container/test/associative_test_data.hpp | 22 ++++++++++++++++-
trunk/libs/ptr_container/test/ptr_array.cpp | 12 ++++++++
trunk/libs/ptr_container/test/ptr_deque.cpp | 13 +++++++++
trunk/libs/ptr_container/test/ptr_list.cpp | 12 +++++++++
trunk/libs/ptr_container/test/ptr_map.cpp | 50 +++++++++++++++++++++++++++++++++++++++
trunk/libs/ptr_container/test/ptr_set.cpp | 22 ++++++++++++++++
trunk/libs/ptr_container/test/ptr_vector.cpp | 23 ++++++++++++++++++
trunk/libs/ptr_container/test/sequence_test_data.hpp | 11 ++++++++
trunk/libs/ptr_container/test/test_data.hpp | 25 ++++++++++++++++++++
9 files changed, 183 insertions(+), 7 deletions(-)
Modified: trunk/libs/ptr_container/test/associative_test_data.hpp
==============================================================================
--- trunk/libs/ptr_container/test/associative_test_data.hpp (original)
+++ trunk/libs/ptr_container/test/associative_test_data.hpp 2007-10-25 16:49:02 EDT (Thu, 25 Oct 2007)
@@ -43,6 +43,7 @@
a_copy = c;
a_copy = a_copy;
BOOST_CHECK( a_copy.empty() );
+
BOOST_MESSAGE( "finished copying test" );
BOOST_DEDUCED_TYPENAME C::allocator_type alloc = c.get_allocator();
@@ -73,11 +74,22 @@
c3.insert( c.begin(), c.end() );
c.erase( c.begin() );
c3.erase( c3.begin(), c3.end() );
+ t = new T;
+ c.insert( new T );
+ c.erase( *t );
BOOST_CHECK( c3.empty() );
c.swap( c3 );
BOOST_CHECK( !c3.empty() );
+ BOOST_CHECK( c.empty() );
c3.clear();
+ //
+ // remark: we cannot pass c3 directly as it would
+ // extract const iterators ... and the
+ // current standard does not allow erase()
+ // to be given const iterators
+ //
+ c3.erase( boost::make_iterator_range(c3) );
BOOST_CHECK( c3.empty() );
BOOST_MESSAGE( "finished modifiers test" );
@@ -97,8 +109,14 @@
#endif
c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3 );
BOOST_CHECK( c3.empty() == false );
- c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3.end(), c3 );
- BOOST_CHECK( c3.empty() );
+ c.clear();
+ unsigned long c3size = c3.size();
+ unsigned long num = c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(),
+ c3.end(),
+ c3 );
+ BOOST_CHECK( num > 0 );
+ BOOST_CHECK_EQUAL( num, c.size() );
+ BOOST_CHECK( c3.empty() );
BOOST_CHECK( !c.empty() );
c3. BOOST_NESTED_TEMPLATE transfer<C>( c );
BOOST_CHECK( !c3.empty() );
Modified: trunk/libs/ptr_container/test/ptr_array.cpp
==============================================================================
--- trunk/libs/ptr_container/test/ptr_array.cpp (original)
+++ trunk/libs/ptr_container/test/ptr_array.cpp 2007-10-25 16:49:02 EDT (Thu, 25 Oct 2007)
@@ -91,7 +91,18 @@
BOOST_CHECK_THROW( (vec.replace(10u, new int(0))), bad_ptr_container_operation );
BOOST_CHECK_THROW( (vec.replace(10u, std::auto_ptr<int>(new int(0)))), bad_ptr_container_operation );
BOOST_CHECK_THROW( (vec.replace(0u, 0)), bad_ptr_container_operation );
+
+ ptr_array<Derived_class,2> derived;
+ derived.replace( 0, new Derived_class );
+ derived.replace( 1, new Derived_class );
+ ptr_array<Base,2> base( derived );
+ BOOST_MESSAGE( "finished derived to base test" );
+
+ base = derived;
+ ptr_array<Base,2> base2( base );
+ base2 = base;
+ base = base;
}
template< class C, class B, class T >
@@ -144,7 +155,6 @@
BOOST_CHECK_EQUAL( c3.is_null(i), true );
BOOST_MESSAGE( "finished element access test" );
-
}
using boost::unit_test::test_suite;
Modified: trunk/libs/ptr_container/test/ptr_deque.cpp
==============================================================================
--- trunk/libs/ptr_container/test/ptr_deque.cpp (original)
+++ trunk/libs/ptr_container/test/ptr_deque.cpp 2007-10-25 16:49:02 EDT (Thu, 25 Oct 2007)
@@ -20,8 +20,19 @@
reversible_container_test< ptr_deque< nullable<Base> >, Base, Derived_class >();
reversible_container_test< ptr_deque< nullable<Value> >, Value, Value >();
- test_transfer< ptr_deque<Derived_class>, ptr_deque<Base>, Derived_class>();
+ container_assignment_test< ptr_deque<Base>, ptr_deque<Derived_class>,
+ Derived_class>();
+ container_assignment_test< ptr_deque< nullable<Base> >,
+ ptr_deque< nullable<Derived_class> >,
+ Derived_class>();
+ container_assignment_test< ptr_deque< nullable<Base> >,
+ ptr_deque<Derived_class>,
+ Derived_class>();
+ container_assignment_test< ptr_deque<Base>,
+ ptr_deque< nullable<Derived_class> >,
+ Derived_class>();
+ test_transfer< ptr_deque<Derived_class>, ptr_deque<Base>, Derived_class>();
random_access_algorithms_test< ptr_deque<int> >();
ptr_deque<int> di;
Modified: trunk/libs/ptr_container/test/ptr_list.cpp
==============================================================================
--- trunk/libs/ptr_container/test/ptr_list.cpp (original)
+++ trunk/libs/ptr_container/test/ptr_list.cpp 2007-10-25 16:49:02 EDT (Thu, 25 Oct 2007)
@@ -24,6 +24,18 @@
reversible_container_test< ptr_list< nullable<Base> >, Base, Derived_class >();
reversible_container_test< ptr_list< nullable<Value> >, Value, Value >();
+ container_assignment_test< ptr_list<Base>, ptr_list<Derived_class>,
+ Derived_class>();
+ container_assignment_test< ptr_list< nullable<Base> >,
+ ptr_list< nullable<Derived_class> >,
+ Derived_class>();
+ container_assignment_test< ptr_list< nullable<Base> >,
+ ptr_list<Derived_class>,
+ Derived_class>();
+ container_assignment_test< ptr_list<Base>,
+ ptr_list< nullable<Derived_class> >,
+ Derived_class>();
+
test_transfer< ptr_list<Derived_class>, ptr_list<Base>, Derived_class>();
random_access_algorithms_test< ptr_list<int> >();
Modified: trunk/libs/ptr_container/test/ptr_map.cpp
==============================================================================
--- trunk/libs/ptr_container/test/ptr_map.cpp (original)
+++ trunk/libs/ptr_container/test/ptr_map.cpp 2007-10-25 16:49:02 EDT (Thu, 25 Oct 2007)
@@ -9,8 +9,8 @@
// For more information, see http://www.boost.org/libs/ptr_container/
//
-#include <boost/test/unit_test.hpp>
#include "test_data.hpp"
+#include <boost/test/unit_test.hpp>
#include <boost/ptr_container/exception.hpp>
#include <boost/range/sub_range.hpp>
#include <boost/cast.hpp>
@@ -261,6 +261,34 @@
+template< class BaseContainer, class DerivedContainer, class Derived >
+void map_container_assignment_test()
+{
+ DerivedContainer derived;
+ std::string foo( "foo" );
+ std::string bar( "foo" );
+ derived.insert( foo, new Derived );
+ derived.insert( bar, new Derived );
+
+ BaseContainer base_container( derived );
+ BOOST_CHECK_EQUAL( derived.size(), base_container.size() );
+ base_container.clear();
+ //
+ // Compilers choke on this one claming that the copy-constructor
+ // must be public! Go figure.
+ //
+ // base_container = derived;
+ //BOOST_CHECK_EQUAL( derived.size(), base_container.size() );
+ //
+ BaseContainer base2( base_container );
+ BOOST_CHECK_EQUAL( base2.size(), base_container.size() );
+ base2 = base_container;
+ BOOST_CHECK_EQUAL( base2.size(), base_container.size() );
+ base_container = base_container;
+}
+
+
+
#include <boost/ptr_container/ptr_map.hpp>
using namespace std;
@@ -278,6 +306,26 @@
ptr_map_test< ptr_multimap<int, nullable<Base> >, Base, Derived_class >();
ptr_map_test< ptr_multimap<int, nullable<Value> >, Value, Value >();
+ map_container_assignment_test< ptr_map<std::string,Base>,
+ ptr_map<std::string,Derived_class>,
+ Derived_class>();
+ map_container_assignment_test< ptr_map<std::string, nullable<Base> >,
+ ptr_map<std::string,Derived_class>,
+ Derived_class>();
+ map_container_assignment_test< ptr_map<std::string, nullable<Base> >,
+ ptr_map<std::string, nullable<Derived_class> >,
+ Derived_class>();
+ map_container_assignment_test< ptr_multimap<std::string,Base>,
+ ptr_multimap<std::string,Derived_class>,
+ Derived_class>();
+ map_container_assignment_test< ptr_multimap<std::string, nullable<Base> >,
+ ptr_multimap<std::string,Derived_class>,
+ Derived_class>();
+ map_container_assignment_test< ptr_multimap<std::string, nullable<Base> >,
+ ptr_multimap<std::string, nullable<Derived_class> >,
+ Derived_class>();
+
+
test_transfer< ptr_map<int,Derived_class>, ptr_map<int,Base>, Derived_class >();
test_transfer< ptr_multimap<int,Derived_class>, ptr_multimap<int,Base>, Derived_class >();
Modified: trunk/libs/ptr_container/test/ptr_set.cpp
==============================================================================
--- trunk/libs/ptr_container/test/ptr_set.cpp (original)
+++ trunk/libs/ptr_container/test/ptr_set.cpp 2007-10-25 16:49:02 EDT (Thu, 25 Oct 2007)
@@ -23,15 +23,35 @@
transfer_test( from, to );
}
+template< class BaseContainer, class DerivedContainer, class Derived >
+void test_copy()
+{
+ DerivedContainer derived;
+ derived.insert( new Derived );
+ derived.insert( new Derived );
+
+ BaseContainer base( derived );
+ BOOST_CHECK_EQUAL( derived.size(), base.size() );
+ base.clear();
+ base = derived;
+ BOOST_CHECK_EQUAL( derived.size(), base.size() );
+ base = base;
+}
+
void test_set()
{
-
+ srand( 0 );
ptr_set_test< ptr_set<Base>, Base, Derived_class >();
ptr_set_test< ptr_set<Value>, Value, Value >();
ptr_set_test< ptr_multiset<Base>, Base, Derived_class >();
ptr_set_test< ptr_multiset<Value>, Value, Value >();
+ test_copy< ptr_set<Base>, ptr_set<Derived_class>,
+ Derived_class>();
+ test_copy< ptr_multiset<Base>, ptr_multiset<Derived_class>,
+ Derived_class>();
+
test_transfer< ptr_set<Derived_class>, ptr_set<Base>, Derived_class>();
test_transfer< ptr_multiset<Derived_class>, ptr_multiset<Base>, Derived_class>();
Modified: trunk/libs/ptr_container/test/ptr_vector.cpp
==============================================================================
--- trunk/libs/ptr_container/test/ptr_vector.cpp (original)
+++ trunk/libs/ptr_container/test/ptr_vector.cpp 2007-10-25 16:49:02 EDT (Thu, 25 Oct 2007)
@@ -12,6 +12,7 @@
#include <boost/test/unit_test.hpp>
#include "sequence_test_data.hpp"
#include <boost/ptr_container/ptr_vector.hpp>
+#include <boost/ptr_container/ptr_list.hpp>
#include <boost/assign/list_inserter.hpp>
void test_ptr_vector()
@@ -25,7 +26,21 @@
reversible_container_test< ptr_vector< nullable<Value> >, Value, Value >();
#endif
+ container_assignment_test< ptr_vector<Base>, ptr_vector<Derived_class>,
+ Derived_class>();
+ container_assignment_test< ptr_vector< nullable<Base> >,
+ ptr_vector< nullable<Derived_class> >,
+ Derived_class>();
+ container_assignment_test< ptr_vector< nullable<Base> >,
+ ptr_vector<Derived_class>,
+ Derived_class>();
+ container_assignment_test< ptr_vector<Base>,
+ ptr_vector< nullable<Derived_class> >,
+ Derived_class>();
+
test_transfer< ptr_vector<Derived_class>, ptr_vector<Base>, Derived_class>();
+ test_transfer< ptr_vector<Derived_class>, ptr_list<Base>, Derived_class>();
+
random_access_algorithms_test< ptr_vector<int> >();
@@ -63,6 +78,14 @@
BOOST_CHECK( vec2 < vec );
BOOST_CHECK( vec2 <= vec );
BOOST_CHECK( vec >= vec2 );
+
+ const int data_size = 10;
+ int** array = new int*[data_size];
+ for( int i = 0; i != data_size; ++i )
+ array[i] = new int(i);
+
+ vec.transfer( vec.begin(), array, data_size );
+ array = vec.c_array();
}
Modified: trunk/libs/ptr_container/test/sequence_test_data.hpp
==============================================================================
--- trunk/libs/ptr_container/test/sequence_test_data.hpp (original)
+++ trunk/libs/ptr_container/test/sequence_test_data.hpp 2007-10-25 16:49:02 EDT (Thu, 25 Oct 2007)
@@ -104,6 +104,7 @@
c3.insert( c3.end(), c.begin(), c.end() );
c.erase( c.begin() );
c3.erase( c3.begin(), c3.end() );
+ c3.erase( boost::make_iterator_range(c3) );
BOOST_CHECK( c3.empty() );
c.swap( c3 );
BOOST_CHECK( !c3.empty() );
@@ -145,8 +146,16 @@
c3. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c );
BOOST_CHECK( !c3.empty() );
BOOST_CHECK( c.empty() );
-
BOOST_MESSAGE( "finished transfer test" );
+
+ c3.resize( 0u );
+ BOOST_CHECK( c3.empty() );
+ c3.resize( 10u );
+ BOOST_CHECK_EQUAL( c3.size(), 10u );
+ c3.resize( 12u, &*c3.begin() );
+ BOOST_CHECK_EQUAL( c3.size(), 12u );
+ BOOST_MESSAGE( "finished resize test" );
+
}
Modified: trunk/libs/ptr_container/test/test_data.hpp
==============================================================================
--- trunk/libs/ptr_container/test/test_data.hpp (original)
+++ trunk/libs/ptr_container/test/test_data.hpp 2007-10-25 16:49:02 EDT (Thu, 25 Oct 2007)
@@ -255,3 +255,28 @@
BOOST_CHECK( !to.empty() );
}
+
+//
+// test of copy operations
+//
+
+template< class BaseContainer, class DerivedContainer, class Derived >
+void container_assignment_test()
+{
+ DerivedContainer derived;
+ derived.insert( derived.begin(), new Derived );
+ derived.insert( derived.begin(), new Derived );
+
+ BaseContainer base( derived );
+ BOOST_CHECK_EQUAL( derived.size(), base.size() );
+ base.clear();
+ base = derived;
+ BOOST_CHECK_EQUAL( derived.size(), base.size() );
+ BaseContainer base2( base );
+ BOOST_CHECK_EQUAL( base2.size(), base.size() );
+ base2 = base;
+ BOOST_CHECK_EQUAL( base2.size(), base.size() );
+ base = base;
+}
+
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk