test_contained_class.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // test_contained_class.cpp
  3. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  4. // Use, modification and distribution is subject to the Boost Software
  5. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // should pass compilation and execution
  8. #include <cstddef>
  9. #include <fstream>
  10. #include <cstdio> // remove
  11. #include <boost/config.hpp>
  12. #if defined(BOOST_NO_STDC_NAMESPACE)
  13. namespace std{
  14. using ::remove;
  15. }
  16. #endif
  17. #include "test_tools.hpp"
  18. #include <boost/serialization/nvp.hpp>
  19. #include "B.hpp"
  20. #include "A.ipp"
  21. ///////////////////////////////////////////////////////
  22. // Contained class
  23. class C
  24. {
  25. private:
  26. friend class boost::serialization::access;
  27. template<class Archive>
  28. void serialize(Archive & ar, const unsigned int /* file_version */){
  29. ar & BOOST_SERIALIZATION_NVP(b);
  30. }
  31. B b;
  32. public:
  33. bool operator==(const C &rhs) const
  34. {
  35. return b == rhs.b;
  36. }
  37. C(){}
  38. };
  39. int test_main( int /* argc */, char* /* argv */[] )
  40. {
  41. const char * testfile = boost::archive::tmpnam(NULL);
  42. BOOST_REQUIRE(NULL != testfile);
  43. const C c;
  44. C c1;
  45. {
  46. test_ostream os(testfile, TEST_STREAM_FLAGS);
  47. test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
  48. oa << boost::serialization::make_nvp("c", c);
  49. }
  50. {
  51. test_istream is(testfile, TEST_STREAM_FLAGS);
  52. test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
  53. ia >> boost::serialization::make_nvp("c", c1);
  54. }
  55. BOOST_CHECK(c == c1);
  56. std::remove(testfile);
  57. return EXIT_SUCCESS;
  58. }
  59. // EOF