• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Boost.Pointer Container
3 //
4 //  Copyright Thorsten Ottosen 2003-2005. Use, modification and
5 //  distribution is subject to the Boost Software License, Version
6 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 //  http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // For more information, see http://www.boost.org/libs/ptr_container/
10 //
11 
12 #include <boost/test/unit_test.hpp>
13 #include "sequence_test_data.hpp"
14 #include <boost/ptr_container/ptr_vector.hpp>
15 #include <boost/ptr_container/ptr_list.hpp>
16 #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
17 #include <boost/assign/list_inserter.hpp>
18 
19 #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
20 #pragma GCC diagnostic push
21 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
22 #endif
23 
test_ptr_vector()24 void test_ptr_vector()
25 {
26     reversible_container_test< ptr_vector<Base>, Base, Derived_class >();
27     reversible_container_test< ptr_vector<Value>, Value, Value >();
28 
29 #ifdef BOOST_NO_SFINAE
30 #else
31     reversible_container_test< ptr_vector< nullable<Base> >, Base, Derived_class >();
32     reversible_container_test< ptr_vector< nullable<Value> >, Value, Value >();
33 #endif
34 
35     container_assignment_test< ptr_vector<Base>, ptr_vector<Derived_class>,
36                                Derived_class>();
37     container_assignment_test< ptr_vector< nullable<Base> >,
38                                ptr_vector< nullable<Derived_class> >,
39                                Derived_class>();
40     container_assignment_test< ptr_vector< nullable<Base> >,
41                                ptr_vector<Derived_class>,
42                                Derived_class>();
43     container_assignment_test< ptr_vector<Base>,
44                                ptr_vector< nullable<Derived_class> >,
45                                Derived_class>();
46 
47     test_transfer< ptr_vector<Derived_class>, ptr_vector<Base>, Derived_class>();
48     test_transfer< ptr_vector<Derived_class>, ptr_list<Base>, Derived_class>();
49 
50     random_access_algorithms_test< ptr_vector<int> >();
51 
52 
53     ptr_vector<int> vec( 100u );
54     BOOST_CHECK( vec.capacity() >= 100u );
55 
56 #ifdef BOOST_PTR_CONTAINER_NO_EXCEPTIONS
57 #else
58 
59     BOOST_CHECK_THROW( vec.push_back(0), bad_ptr_container_operation );
60     BOOST_CHECK_THROW( (vec.insert( vec.begin(), 0 )), bad_ptr_container_operation );
61     BOOST_CHECK_THROW( vec.at( 42 ), bad_ptr_container_operation );
62     vec.push_back( new int(0) );
63     BOOST_CHECK_THROW( (vec.replace(10u, new int(0))), bad_ptr_container_operation );
64     BOOST_CHECK_THROW( (vec.replace(0u, 0)), bad_ptr_container_operation );
65     BOOST_CHECK_THROW( (vec.replace(vec.begin(), 0 )), bad_ptr_container_operation );
66 
67 #endif
68 
69     vec.clear();
70     assign::push_back( vec )( new int(2) )
71                             ( new int(4) )
72                             ( new int(6) )
73                             ( new int(8) );
74     ptr_vector<int> vec2;
75     assign::push_back( vec2 )
76                         ( new int(1) )
77                         ( new int(3) )
78                         ( new int(5) )
79                         ( new int(7) );
80     BOOST_CHECK_EQUAL( vec.size(), vec2.size() );
81     BOOST_CHECK( vec > vec2 );
82     BOOST_CHECK( vec != vec2 );
83     BOOST_CHECK( !(vec == vec2) );
84     BOOST_CHECK( vec2 < vec );
85     BOOST_CHECK( vec2 <= vec );
86     BOOST_CHECK( vec >= vec2 );
87 
88     const int data_size = 10;
89     int** array = new int*[data_size];
90     for( int i = 0; i != data_size; ++i )
91         array[i] = new int(i);
92 
93     vec.transfer( vec.begin(), array, data_size );
94     int** array2 = vec.c_array();
95     BOOST_CHECK( array2 != array );
96 
97 }
98 
99 #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
100 #pragma GCC diagnostic pop
101 #endif
102 
103 using boost::unit_test::test_suite;
104 
init_unit_test_suite(int argc,char * argv[])105 test_suite* init_unit_test_suite( int argc, char* argv[] )
106 {
107     test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" );
108 
109     test->add( BOOST_TEST_CASE( &test_ptr_vector ) );
110 
111     return test;
112 }
113