| 1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
|---|
| 2 | // test_null_ptr.cpp: test implementation level trait |
|---|
| 3 | |
|---|
| 4 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
|---|
| 5 | // Use, modification and distribution is subject to the Boost Software |
|---|
| 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 8 | |
|---|
| 9 | // should pass compilation and execution |
|---|
| 10 | |
|---|
| 11 | #include <fstream> |
|---|
| 12 | |
|---|
| 13 | #include <cstdio> // remove |
|---|
| 14 | #include <boost/config.hpp> |
|---|
| 15 | #if defined(BOOST_NO_STDC_NAMESPACE) |
|---|
| 16 | namespace std{ |
|---|
| 17 | using ::remove; |
|---|
| 18 | } |
|---|
| 19 | #endif |
|---|
| 20 | |
|---|
| 21 | #include "test_tools.hpp" |
|---|
| 22 | #include <boost/preprocessor/stringize.hpp> |
|---|
| 23 | #include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST) |
|---|
| 24 | #include <boost/serialization/base_object.hpp> |
|---|
| 25 | |
|---|
| 26 | class polymorphic_base |
|---|
| 27 | { |
|---|
| 28 | friend class boost::serialization::access; |
|---|
| 29 | template<class Archive> |
|---|
| 30 | void serialize(Archive & /* ar */, const unsigned int /* file_version */){ |
|---|
| 31 | } |
|---|
| 32 | public: |
|---|
| 33 | virtual ~polymorphic_base(){}; |
|---|
| 34 | }; |
|---|
| 35 | |
|---|
| 36 | class polymorphic_derived1 : public polymorphic_base |
|---|
| 37 | { |
|---|
| 38 | friend class boost::serialization::access; |
|---|
| 39 | template<class Archive> |
|---|
| 40 | void serialize(Archive &ar, const unsigned int /* file_version */){ |
|---|
| 41 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base); |
|---|
| 42 | } |
|---|
| 43 | }; |
|---|
| 44 | |
|---|
| 45 | // save unregistered polymorphic classes |
|---|
| 46 | void save(const char *testfile) |
|---|
| 47 | { |
|---|
| 48 | test_ostream os(testfile, TEST_STREAM_FLAGS); |
|---|
| 49 | test_oarchive oa(os); |
|---|
| 50 | |
|---|
| 51 | polymorphic_base *rb1 = NULL; |
|---|
| 52 | polymorphic_derived1 *rd1 = NULL; |
|---|
| 53 | |
|---|
| 54 | oa << BOOST_SERIALIZATION_NVP(rb1); |
|---|
| 55 | oa << BOOST_SERIALIZATION_NVP(rd1); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | // load unregistered polymorphic classes |
|---|
| 59 | void load(const char *testfile) |
|---|
| 60 | { |
|---|
| 61 | test_istream is(testfile, TEST_STREAM_FLAGS); |
|---|
| 62 | test_iarchive ia(is); |
|---|
| 63 | |
|---|
| 64 | polymorphic_base *rb1 = (polymorphic_base *)0xfffffff; |
|---|
| 65 | polymorphic_derived1 *rd1 = (polymorphic_derived1 *)0xffffffff; |
|---|
| 66 | |
|---|
| 67 | ia >> BOOST_SERIALIZATION_NVP(rb1); |
|---|
| 68 | BOOST_CHECK_MESSAGE(NULL == rb1, "Null pointer not restored"); |
|---|
| 69 | |
|---|
| 70 | ia >> BOOST_SERIALIZATION_NVP(rd1); |
|---|
| 71 | BOOST_CHECK_MESSAGE(NULL == rd1, "Null pointer not restored"); |
|---|
| 72 | |
|---|
| 73 | delete rb1; |
|---|
| 74 | delete rd1; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | int |
|---|
| 78 | test_main( int /* argc */, char* /* argv */[] ) |
|---|
| 79 | { |
|---|
| 80 | const char * testfile = boost::archive::tmpnam(NULL); |
|---|
| 81 | BOOST_REQUIRE(NULL != testfile); |
|---|
| 82 | save(testfile); |
|---|
| 83 | load(testfile); |
|---|
| 84 | std::remove(testfile); |
|---|
| 85 | return EXIT_SUCCESS; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | // EOF |
|---|