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