1 // (C) Copyright 2009 Brian Ravnsgaard and Kenneth Riddile
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 // See http://www.boost.org for most recent version including documentation.
7
8 // Test that serialization of std::bitset works.
9 // Should pass compilation and execution
10 // 16.09.2004, updated 04.03.2009
11
12 #include <cstddef> // NULL
13 #include <cstdio> // remove
14 #include <fstream>
15
16 #include <boost/config.hpp>
17
18 #if defined( BOOST_NO_STDC_NAMESPACE )
19 namespace std
20 {
21 using ::remove;
22 }
23 #endif
24
25 #include "test_tools.hpp"
26
27 #include <boost/serialization/bitset.hpp>
28 #include <boost/serialization/nvp.hpp>
29
test_main(int,char * [])30 int test_main( int /* argc */, char* /* argv */[] )
31 {
32 const char* testfile = boost::archive::tmpnam( NULL );
33 BOOST_REQUIRE( NULL != testfile );
34
35 std::bitset<8> bitsetA;
36 bitsetA.set( 0, false );
37 bitsetA.set( 1, true );
38 bitsetA.set( 2, false );
39 bitsetA.set( 3, true );
40 bitsetA.set( 4, false );
41 bitsetA.set( 5, false );
42 bitsetA.set( 6, true );
43 bitsetA.set( 7, true );
44
45 {
46 test_ostream os( testfile, TEST_STREAM_FLAGS );
47 test_oarchive oa( os );
48 oa << boost::serialization::make_nvp( "bitset", bitsetA );
49 }
50
51 std::bitset<8> bitsetB;
52 {
53 test_istream is( testfile, TEST_STREAM_FLAGS );
54 test_iarchive ia( is );
55 ia >> boost::serialization::make_nvp( "bitset", bitsetB );
56 }
57
58 BOOST_CHECK( bitsetA == bitsetB );
59
60 std::remove( testfile );
61 return EXIT_SUCCESS;
62 }
63
64 // EOF
65