test_object.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // test_object.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. // test implementation level "object_serializable"
  8. // should pass compilation and execution
  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. using ::remove;
  16. }
  17. #endif
  18. #include "test_tools.hpp"
  19. #include <boost/serialization/level.hpp>
  20. #include <boost/serialization/nvp.hpp>
  21. class A
  22. {
  23. friend class boost::serialization::access;
  24. template<class Archive>
  25. void serialize(Archive & /* ar */, const unsigned int /* file_version */){
  26. }
  27. };
  28. BOOST_CLASS_IMPLEMENTATION(A, boost::serialization::object_serializable)
  29. // note: version can be assigned only to objects whose implementation
  30. // level is object_class_info. So, doing the following will result in
  31. // a static assertion
  32. // BOOST_CLASS_VERSION(A, 2);
  33. void out(const char *testfile, A & a)
  34. {
  35. test_ostream os(testfile, TEST_STREAM_FLAGS);
  36. test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
  37. oa << BOOST_SERIALIZATION_NVP(a);
  38. }
  39. void in(const char *testfile, A & a)
  40. {
  41. test_istream is(testfile, TEST_STREAM_FLAGS);
  42. test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
  43. ia >> BOOST_SERIALIZATION_NVP(a);
  44. }
  45. int
  46. test_main( int /* argc */, char* /* argv */[] )
  47. {
  48. const char * testfile = boost::archive::tmpnam(NULL);
  49. BOOST_REQUIRE(NULL != testfile);
  50. A a;
  51. out(testfile, a);
  52. in(testfile, a);
  53. std::remove(testfile);
  54. return EXIT_SUCCESS;
  55. }
  56. // EOF