test_bitset.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. // See http://www.boost.org for most recent version including documentation.
  6. // Test that serialization of std::bitset works.
  7. // Should pass compilation and execution
  8. // 16.09.2004, updated 04.03.2009
  9. #include <cstddef> // NULL
  10. #include <cstdio> // remove
  11. #include <fstream>
  12. #include <boost/config.hpp>
  13. #if defined( BOOST_NO_STDC_NAMESPACE )
  14. namespace std
  15. {
  16. using ::remove;
  17. }
  18. #endif
  19. #include "test_tools.hpp"
  20. #include <boost/serialization/bitset.hpp>
  21. #include <boost/serialization/nvp.hpp>
  22. int test_main( int /* argc */, char* /* argv */[] )
  23. {
  24. const char* testfile = boost::archive::tmpnam( NULL );
  25. BOOST_REQUIRE( NULL != testfile );
  26. std::bitset<8> bitsetA;
  27. bitsetA.set( 0, false );
  28. bitsetA.set( 1, true );
  29. bitsetA.set( 2, false );
  30. bitsetA.set( 3, true );
  31. bitsetA.set( 4, false );
  32. bitsetA.set( 5, false );
  33. bitsetA.set( 6, true );
  34. bitsetA.set( 7, true );
  35. {
  36. test_ostream os( testfile, TEST_STREAM_FLAGS );
  37. test_oarchive oa( os );
  38. oa << boost::serialization::make_nvp( "bitset", bitsetA );
  39. }
  40. std::bitset<8> bitsetB;
  41. {
  42. test_istream is( testfile, TEST_STREAM_FLAGS );
  43. test_iarchive ia( is );
  44. ia >> boost::serialization::make_nvp( "bitset", bitsetB );
  45. }
  46. BOOST_CHECK( bitsetA == bitsetB );
  47. std::remove( testfile );
  48. return EXIT_SUCCESS;
  49. }
  50. // EOF