]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/serialization/test/test_class_info_load.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / serialization / test / test_class_info_load.cpp
CommitLineData
7c673cae
FG
1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2// test_class_info_load.cpp: test implementation level trait
3
f67539c2 4// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
7c673cae
FG
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_class_info"
10// should pass compilation and execution
11
12#include <string>
13#include <fstream>
14
15#include <boost/archive/tmpdir.hpp>
16#include <boost/preprocessor/stringize.hpp>
17#include "test_tools.hpp"
18
19#include <boost/static_assert.hpp>
20#include <boost/serialization/level.hpp>
21#include <boost/serialization/tracking.hpp>
22#include <boost/serialization/version.hpp>
23#include <boost/serialization/nvp.hpp>
24
25class A
26{
27 friend class boost::serialization::access;
28 template<class Archive>
29 void serialize(Archive & /*ar*/, const unsigned int file_version){
30 // class that don't save class info always have a version number of 0
31 BOOST_CHECK(file_version == 0);
32 BOOST_STATIC_ASSERT(0 == ::boost::serialization::version<A>::value);
33 ++count;
34 }
35public:
36 unsigned int count;
37 A() : count(0) {}
38};
39
40BOOST_CLASS_IMPLEMENTATION(A, ::boost::serialization::object_serializable)
41BOOST_CLASS_TRACKING(A, ::boost::serialization::track_never)
42
43// second case : serialize WITH class information
44class B
45{
46 friend class boost::serialization::access;
47 template<class Archive>
48 void serialize(Archive & /*ar*/, const unsigned int file_version){
49 // verify at execution that the version number corresponds to the saved
50 // one
51 BOOST_CHECK(file_version == 2);
52 ++count;
53 }
54public:
55 unsigned int count;
56 B() : count(0) {}
57};
58
59BOOST_CLASS_IMPLEMENTATION(B, ::boost::serialization::object_class_info)
60BOOST_CLASS_TRACKING(B, ::boost::serialization::track_never)
61BOOST_CLASS_VERSION(B, 4)
62
63void in(const char *testfile, A & a, B & b)
64{
65 test_istream is(testfile, TEST_STREAM_FLAGS);
66 test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
67 ia >> BOOST_SERIALIZATION_NVP(a);
68 ia >> BOOST_SERIALIZATION_NVP(a);
69 BOOST_CHECK(a.count == 2); // no tracking => redundant loads
70 ia >> BOOST_SERIALIZATION_NVP(b);
71 ia >> BOOST_SERIALIZATION_NVP(b);
72 // note: archive was saved with tracking so that is what determines
73 // whether tracking is perform on load - regardless of the latest
74 // tracking setting.
75 BOOST_CHECK(b.count == 1);
76}
77
78int
79test_main( int /* argc */, char* /* argv */[] )
80{
81 A a;
82 B b;
83 std::string filename;
84 filename += boost::archive::tmpdir();
85 filename += '/';
86 filename += BOOST_PP_STRINGIZE(testfile_);
87 filename += BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST);
88 in(filename.c_str(), a, b);
89 return EXIT_SUCCESS;
90}
91
92// EOF