File: dyn_bitset_unit_tests5.cpp

package info (click to toggle)
boost1.74 1.74.0%2Bds1-21
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 463,588 kB
  • sloc: cpp: 3,338,117; xml: 131,293; python: 33,088; ansic: 14,292; asm: 4,038; sh: 3,353; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (112 lines) | stat: -rw-r--r-- 3,216 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// -----------------------------------------------------------
//              Copyright (c) 2001 Jeremy Siek
//           Copyright (c) 2003-2006 Gennaro Prota
//
// Copyright (c) 2015 Seth Heeren
//
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)
//
// -----------------------------------------------------------

#include "boost/config.hpp"
#if !defined (BOOST_NO_STRINGSTREAM)
# include <sstream>
#endif

#include "bitset_test.hpp"
#include <boost/dynamic_bitset/serialization.hpp>
#include <boost/config/workaround.hpp>


// Codewarrior 8.3 for Win fails without this.
// Thanks Howard Hinnant ;)
#if defined __MWERKS__ && BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
# pragma parse_func_templ off
#endif


#if defined BOOST_NO_STD_WSTRING || defined BOOST_NO_STD_LOCALE
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
#endif

#include <boost/serialization/vector.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <sstream>

namespace {
    template <typename Block>
        struct SerializableType {
            boost::dynamic_bitset<Block> x;

          private:
            friend class boost::serialization::access;
            template <class Archive> void serialize(Archive &ar, const unsigned int) {
                ar & BOOST_SERIALIZATION_NVP(x);
            }
        };

    template <typename Block, typename IArchive, typename OArchive>
        void test_serialization( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
        {
            SerializableType<Block> a;

            for (int i=0; i<128; ++i)
                a.x.resize(11*i, i%2);

#if !defined (BOOST_NO_STRINGSTREAM)
            std::stringstream ss;

            // test serialization
            {
                OArchive oa(ss);
                oa << BOOST_SERIALIZATION_NVP(a);
            }

            // test de-serialization
            {
                IArchive ia(ss);
                SerializableType<Block> b;
                ia >> BOOST_SERIALIZATION_NVP(b);

                assert(a.x == b.x);
            }
#else
#           error "TODO implement file-based test path?"
#endif
        }

    template <typename Block>
        void test_binary_archive( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) {
            test_serialization<Block, boost::archive::binary_iarchive, boost::archive::binary_oarchive>();
        }

    template <typename Block>
        void test_xml_archive( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) {
            test_serialization<Block, boost::archive::xml_iarchive, boost::archive::xml_oarchive>();
        }
}

template <typename Block>
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
{
    test_binary_archive<Block>();
    test_xml_archive<Block>();
}

int main()
{
    run_test_cases<unsigned char>();
    run_test_cases<unsigned short>();
    run_test_cases<unsigned int>();
    run_test_cases<unsigned long>();
# ifdef BOOST_HAS_LONG_LONG
    run_test_cases< ::boost::ulong_long_type>();
# endif

    return boost::report_errors();
}