Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/serialization/test/test_set.cpp @ 33

Last change on this file since 33 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 3.6 KB
Line 
1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2// test_set.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 <algorithm>
12#include <vector>
13#include <fstream>
14
15#include <cstdio> // remove
16#include <boost/config.hpp>
17
18#include <boost/detail/workaround.hpp>
19#if defined(BOOST_NO_STDC_NAMESPACE)
20namespace std{ 
21    using ::remove;
22}
23#endif
24
25#include <boost/archive/archive_exception.hpp>
26
27#include "test_tools.hpp"
28#include <boost/preprocessor/stringize.hpp>
29#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
30
31#include <boost/serialization/set.hpp>
32
33#include "A.hpp"
34
35#ifdef BOOST_HAS_HASH
36#include <boost/serialization/hash_set.hpp>
37
38/*
39#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
40#define STD _STLP_STD
41#else
42#define STD BOOST_STD_EXTENSION_NAMESPACE
43#endif
44*/
45namespace BOOST_STD_EXTENSION_NAMESPACE {
46    template<>
47    struct hash<A> {
48        std::size_t operator()(const A& a) const {
49            return (std::size_t)a;
50        }
51    };
52}
53
54#endif
55
56int test_main( int /* argc */, char* /* argv */[] )
57{
58    const char * testfile = boost::archive::tmpnam(NULL);
59    BOOST_REQUIRE(NULL != testfile);
60
61    // test array of objects
62    std::set<A> aset;
63    aset.insert(A());
64    aset.insert(A());
65    {   
66        test_ostream os(testfile, TEST_STREAM_FLAGS);
67        test_oarchive oa(os);
68        oa << boost::serialization::make_nvp("aset", aset);
69    }
70    std::set<A> aset1;
71    {
72        test_istream is(testfile, TEST_STREAM_FLAGS);
73        test_iarchive ia(is);
74        ia >> boost::serialization::make_nvp("aset", aset1);
75    }
76    BOOST_CHECK(aset == aset1);
77   
78    std::multiset<A> amultiset;
79    amultiset.insert(A());
80    amultiset.insert(A());
81    {   
82        test_ostream os(testfile, TEST_STREAM_FLAGS);
83        test_oarchive oa(os);
84        oa << boost::serialization::make_nvp("amultiset", amultiset);
85    }
86    std::multiset<A> amultiset1;
87    {
88        test_istream is(testfile, TEST_STREAM_FLAGS);
89        test_iarchive ia(is);
90        ia >> boost::serialization::make_nvp("amultiset", amultiset1);
91    }
92    BOOST_CHECK(amultiset == amultiset1);
93   
94    #ifdef BOOST_HAS_HASH
95
96    // test array of objects
97    BOOST_STD_EXTENSION_NAMESPACE::hash_set<A> ahash_set;
98    A a, a1;
99    ahash_set.insert(a);
100    ahash_set.insert(a1);
101    {   
102        test_ostream os(testfile, TEST_STREAM_FLAGS);
103        test_oarchive oa(os);
104        oa << boost::serialization::make_nvp("ahash_set", ahash_set);
105    }
106    BOOST_STD_EXTENSION_NAMESPACE::hash_set<A> ahash_set1;
107    {
108        test_istream is(testfile, TEST_STREAM_FLAGS);
109        test_iarchive ia(is);
110        ia >> boost::serialization::make_nvp("ahash_set", ahash_set1);
111    }
112    BOOST_CHECK(ahash_set == ahash_set1);
113
114    BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<A> ahash_multiset;
115    ahash_multiset.insert(A());
116    ahash_multiset.insert(A());
117    {   
118        test_ostream os(testfile, TEST_STREAM_FLAGS);
119        test_oarchive oa(os);
120        oa << boost::serialization::make_nvp("ahash_multiset", ahash_multiset);
121    }
122    BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<A> ahash_multiset1;
123    {
124        test_istream is(testfile, TEST_STREAM_FLAGS);
125        test_iarchive ia(is);
126        ia >> boost::serialization::make_nvp("ahash_multiset", ahash_multiset1);
127    }
128    BOOST_CHECK(ahash_multiset == ahash_multiset1);
129
130    #endif
131
132    std::remove(testfile);
133    return EXIT_SUCCESS;
134}
Note: See TracBrowser for help on using the repository browser.