test_forward_list_ptrs.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // test_list.cpp
  3. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  4. // Use, modification and distribution is subject to the Boost Software
  5. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // should pass compilation and execution
  8. #include <cstddef>
  9. #include <fstream>
  10. #include <boost/config.hpp>
  11. #include <cstdio> // remove
  12. #if defined(BOOST_NO_STDC_NAMESPACE)
  13. namespace std{
  14. using ::remove;
  15. }
  16. #endif
  17. #include <boost/type_traits/is_pointer.hpp>
  18. #include <boost/static_assert.hpp>
  19. #include <boost/checked_delete.hpp>
  20. #include <boost/archive/archive_exception.hpp>
  21. #include "test_tools.hpp"
  22. #include <boost/serialization/nvp.hpp>
  23. #include "A.hpp"
  24. #include "A.ipp"
  25. template<class T>
  26. struct ptr_equal_to {
  27. BOOST_STATIC_ASSERT(::boost::is_pointer< T >::value);
  28. bool operator()(T const _Left, T const _Right) const
  29. {
  30. if(NULL == _Left && NULL == _Right)
  31. return true;
  32. if(typeid(*_Left) != typeid(*_Right))
  33. return false;
  34. return *_Left == *_Right;
  35. }
  36. };
  37. #include <boost/serialization/forward_list.hpp>
  38. void test_forward_list(){
  39. const char * testfile = boost::archive::tmpnam(NULL);
  40. BOOST_REQUIRE(NULL != testfile);
  41. std::forward_list<A *> aslist;
  42. {
  43. test_ostream os(testfile, TEST_STREAM_FLAGS);
  44. test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
  45. aslist.push_front(new A);
  46. aslist.push_front(new A);
  47. oa << boost::serialization::make_nvp("aslist", aslist);
  48. }
  49. std::forward_list<A *> aslist1;
  50. {
  51. test_istream is(testfile, TEST_STREAM_FLAGS);
  52. test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
  53. ia >> boost::serialization::make_nvp("aslist", aslist1);
  54. BOOST_CHECK(
  55. std::equal(
  56. aslist.begin(),
  57. aslist.end(),
  58. aslist1.begin(),
  59. ptr_equal_to<A *>()
  60. )
  61. );
  62. }
  63. std::for_each(
  64. aslist.begin(),
  65. aslist.end(),
  66. boost::checked_deleter<A>()
  67. );
  68. std::for_each(
  69. aslist1.begin(),
  70. aslist1.end(),
  71. boost::checked_deleter<A>()
  72. );
  73. std::remove(testfile);
  74. }
  75. int test_main( int /* argc */, char* /* argv */[] )
  76. {
  77. test_forward_list();
  78. return EXIT_SUCCESS;
  79. }
  80. // EOF