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