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/slist.hpp> |
48 | void test_slist(){ |
49 | const char * testfile = boost::archive::tmpnam(NULL); |
50 | BOOST_REQUIRE(NULL != testfile); |
51 | |
52 | BOOST_STD_EXTENSION_NAMESPACE::slist<A *> aslist; |
53 | { |
54 | test_ostream os(testfile, TEST_STREAM_FLAGS); |
55 | test_oarchive oa(os, TEST_ARCHIVE_FLAGS); |
56 | aslist.push_front(x: new A); |
57 | aslist.push_front(x: new A); |
58 | oa << boost::serialization::make_nvp(n: "aslist" , v&: aslist); |
59 | } |
60 | BOOST_STD_EXTENSION_NAMESPACE::slist<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(n: "aslist" , v&: aslist1); |
65 | BOOST_CHECK(aslist.size() == aslist1.size() && |
66 | std::equal(aslist.begin(),aslist.end(),aslist1.begin(),ptr_equal_to<A *>()) |
67 | ); |
68 | } |
69 | std::for_each( |
70 | first: aslist.begin(), |
71 | last: aslist.end(), |
72 | f: boost::checked_deleter<A>() |
73 | ); |
74 | std::for_each( |
75 | first: aslist1.begin(), |
76 | last: aslist1.end(), |
77 | f: boost::checked_deleter<A>() |
78 | ); |
79 | std::remove(filename: testfile); |
80 | } |
81 | |
82 | int test_main( int /* argc */, char* /* argv */[] ) |
83 | { |
84 | test_slist(); |
85 | return EXIT_SUCCESS; |
86 | } |
87 | |
88 | // EOF |
89 | |