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