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