]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dynamic_bitset/test/dyn_bitset_unit_tests5.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / dynamic_bitset / test / dyn_bitset_unit_tests5.cpp
1 // -----------------------------------------------------------
2 // Copyright (c) 2001 Jeremy Siek
3 // Copyright (c) 2003-2006 Gennaro Prota
4 //
5 // Copyright (c) 2015 Seth Heeren
6 //
7 // Distributed under the Boost Software License, Version 1.0.
8 // (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 //
11 // -----------------------------------------------------------
12
13 #include "boost/config.hpp"
14 #if !defined (BOOST_NO_STRINGSTREAM)
15 # include <sstream>
16 #endif
17
18 #include "bitset_test.hpp"
19 #include "boost/dynamic_bitset/serialization.hpp"
20 #include "boost/detail/workaround.hpp"
21
22
23 // Codewarrior 8.3 for Win fails without this.
24 // Thanks Howard Hinnant ;)
25 #if defined __MWERKS__ && BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
26 # pragma parse_func_templ off
27 #endif
28
29
30 #if defined BOOST_NO_STD_WSTRING || defined BOOST_NO_STD_LOCALE
31 # define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
32 #endif
33
34 #include <boost/archive/binary_oarchive.hpp>
35 #include <boost/archive/binary_iarchive.hpp>
36 #include <boost/archive/xml_oarchive.hpp>
37 #include <boost/archive/xml_iarchive.hpp>
38 #include <sstream>
39
40 namespace {
41 template <typename Block>
42 struct SerializableType {
43 boost::dynamic_bitset<Block> x;
44
45 private:
46 friend class boost::serialization::access;
47 template <class Archive> void serialize(Archive &ar, const unsigned int) {
48 ar & BOOST_SERIALIZATION_NVP(x);
49 }
50 };
51
52 template <typename Block, typename IArchive, typename OArchive>
53 void test_serialization( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
54 {
55 SerializableType<Block> a;
56
57 for (int i=0; i<128; ++i)
58 a.x.resize(11*i, i%2);
59
60 #if !defined (BOOST_NO_STRINGSTREAM)
61 std::stringstream ss;
62
63 // test serialization
64 {
65 OArchive oa(ss);
66 oa << BOOST_SERIALIZATION_NVP(a);
67 }
68
69 // test de-serialization
70 {
71 IArchive ia(ss);
72 SerializableType<Block> b;
73 ia >> BOOST_SERIALIZATION_NVP(b);
74
75 assert(a.x == b.x);
76 }
77 #else
78 # error "TODO implement file-based test path?"
79 #endif
80 }
81
82 template <typename Block>
83 void test_binary_archive( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) {
84 test_serialization<Block, boost::archive::binary_iarchive, boost::archive::binary_oarchive>();
85 }
86
87 template <typename Block>
88 void test_xml_archive( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) {
89 test_serialization<Block, boost::archive::xml_iarchive, boost::archive::xml_oarchive>();
90 }
91 }
92
93 template <typename Block>
94 void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
95 {
96 test_binary_archive<Block>();
97 test_xml_archive<Block>();
98 }
99
100 int test_main(int, char*[])
101 {
102 run_test_cases<unsigned char>();
103 run_test_cases<unsigned short>();
104 run_test_cases<unsigned int>();
105 run_test_cases<unsigned long>();
106 # ifdef BOOST_HAS_LONG_LONG
107 run_test_cases< ::boost::ulong_long_type>();
108 # endif
109
110 return 0;
111 }