ptr_list.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #define PTR_LIST_TEST 1
  12. #define PTR_CONTAINER_DEBUG 0
  13. #include <boost/test/unit_test.hpp>
  14. #include "sequence_test_data.hpp"
  15. #include <boost/ptr_container/ptr_list.hpp>
  16. #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
  17. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  18. #pragma GCC diagnostic push
  19. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  20. #endif
  21. void test_list()
  22. {
  23. reversible_container_test< ptr_list<Base>, Base, Derived_class >();
  24. reversible_container_test< ptr_list<Value>, Value, Value >();
  25. reversible_container_test< ptr_list< nullable<Base> >, Base, Derived_class >();
  26. reversible_container_test< ptr_list< nullable<Value> >, Value, Value >();
  27. container_assignment_test< ptr_list<Base>, ptr_list<Derived_class>,
  28. Derived_class>();
  29. container_assignment_test< ptr_list< nullable<Base> >,
  30. ptr_list< nullable<Derived_class> >,
  31. Derived_class>();
  32. container_assignment_test< ptr_list< nullable<Base> >,
  33. ptr_list<Derived_class>,
  34. Derived_class>();
  35. container_assignment_test< ptr_list<Base>,
  36. ptr_list< nullable<Derived_class> >,
  37. Derived_class>();
  38. test_transfer< ptr_list<Derived_class>, ptr_list<Base>, Derived_class>();
  39. random_access_algorithms_test< ptr_list<int> >();
  40. ptr_list<int> list;
  41. list.push_back( new int(0) );
  42. list.push_back( new int(2) );
  43. list.push_back( new int(1) );
  44. list.push_front( new int(3) );
  45. #ifndef BOOST_NO_AUTO_PTR
  46. list.push_front( std::auto_ptr<int>( new int(42) ) );
  47. #endif
  48. #ifndef BOOST_NO_CXX11_SMART_PTR
  49. list.push_front( std::unique_ptr<int>( new int(43) ) );
  50. #endif
  51. list.reverse();
  52. ptr_list<int>::const_iterator it = list.begin();
  53. BOOST_CHECK(1 == *it++);
  54. BOOST_CHECK(2 == *it++);
  55. BOOST_CHECK(0 == *it++);
  56. BOOST_CHECK(3 == *it++);
  57. #ifndef BOOST_NO_AUTO_PTR
  58. BOOST_CHECK(42 == *it++);
  59. #endif
  60. #ifndef BOOST_NO_CXX11_SMART_PTR
  61. BOOST_CHECK(43 == *it++);
  62. #endif
  63. BOOST_CHECK(list.end() == it);
  64. }
  65. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  66. #pragma GCC diagnostic pop
  67. #endif
  68. using boost::unit_test::test_suite;
  69. test_suite* init_unit_test_suite( int argc, char* argv[] )
  70. {
  71. test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" );
  72. test->add( BOOST_TEST_CASE( &test_list ) );
  73. return test;
  74. }