test_primitive.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // test_primitive.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 "primitive_type"
  8. #include <cstddef> // NULL
  9. #include <fstream>
  10. #include <boost/config.hpp>
  11. #include "test_tools.hpp"
  12. #include <boost/serialization/level.hpp>
  13. #include <boost/serialization/nvp.hpp>
  14. struct A
  15. {
  16. template<class Archive>
  17. void serialize(Archive &ar, const unsigned int /* file_version */){
  18. // note: should never fail here
  19. BOOST_STATIC_ASSERT(0 == sizeof(Archive));
  20. }
  21. };
  22. std::ostream & operator<<(std::ostream &os, const A & /* a */){ return os;}
  23. std::istream & operator>>(std::istream &is, A & /* a */){return is;}
  24. #ifndef BOOST_NO_STD_WSTREAMBUF
  25. std::wostream & operator<<(std::wostream &os, const A & /* a */){ return os;}
  26. std::wistream & operator>>(std::wistream &is, A & /* a */){return is;}
  27. #endif
  28. BOOST_CLASS_IMPLEMENTATION(A, boost::serialization::primitive_type)
  29. void out(const char *testfile, A & a)
  30. {
  31. test_ostream os(testfile, TEST_STREAM_FLAGS);
  32. test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
  33. oa << BOOST_SERIALIZATION_NVP(a);
  34. }
  35. void in(const char *testfile, A & a)
  36. {
  37. test_istream is(testfile, TEST_STREAM_FLAGS);
  38. test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
  39. ia >> BOOST_SERIALIZATION_NVP(a);
  40. }
  41. int
  42. test_main( int /* argc */, char* /* argv */[] )
  43. {
  44. const char * testfile = boost::archive::tmpnam(NULL);
  45. BOOST_REQUIRE(NULL != testfile);
  46. A a;
  47. out(testfile, a);
  48. in(testfile, a);
  49. return EXIT_SUCCESS;
  50. }
  51. // EOF