test_polymorphic2.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // test_polymorphic2.cpp
  3. // (C) Copyright 2009 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 <fstream>
  9. #include "test_tools.hpp"
  10. #include "test_polymorphic2.hpp"
  11. int test_main(int /*argc*/, char* /*argv*/[])
  12. {
  13. A *a = new B();
  14. a->i = 3;
  15. const char * testfile = boost::archive::tmpnam(NULL);
  16. BOOST_REQUIRE(NULL != testfile);
  17. {
  18. test_ostream os(testfile, TEST_STREAM_FLAGS);
  19. test_oarchive oa_implementation(os, TEST_ARCHIVE_FLAGS);
  20. boost::archive::polymorphic_oarchive & opa = oa_implementation;
  21. opa << BOOST_SERIALIZATION_NVP(a);
  22. }
  23. A *loaded = 0;
  24. {
  25. test_istream is(testfile, TEST_STREAM_FLAGS);
  26. test_iarchive ia_implementation(is, TEST_ARCHIVE_FLAGS);
  27. boost::archive::polymorphic_iarchive & ipa = ia_implementation;
  28. ipa >> BOOST_SERIALIZATION_NVP(loaded);
  29. }
  30. BOOST_CHECK(a->i == loaded->i);
  31. delete a;
  32. delete loaded;
  33. return EXIT_SUCCESS;
  34. }