1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
---|
2 | // test_optional.cpp |
---|
3 | |
---|
4 | // (C) Copyright 2004 Pavel Vozenilek |
---|
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 | #include <boost/config.hpp> |
---|
13 | |
---|
14 | #include <cstdio> // remove |
---|
15 | #if defined(BOOST_NO_STDC_NAMESPACE) |
---|
16 | namespace std{ |
---|
17 | using ::remove; |
---|
18 | } |
---|
19 | #endif |
---|
20 | |
---|
21 | |
---|
22 | #include <boost/archive/archive_exception.hpp> |
---|
23 | #include "test_tools.hpp" |
---|
24 | #include <boost/preprocessor/stringize.hpp> |
---|
25 | #include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST) |
---|
26 | |
---|
27 | #include <boost/serialization/optional.hpp> |
---|
28 | |
---|
29 | #include "A.hpp" |
---|
30 | |
---|
31 | int test_main( int /* argc */, char* /* argv */[] ) |
---|
32 | { |
---|
33 | const char * testfile = boost::archive::tmpnam(NULL); |
---|
34 | BOOST_REQUIRE(NULL != testfile); |
---|
35 | |
---|
36 | const boost::optional<int> aoptional1; |
---|
37 | const boost::optional<int> aoptional2(123); |
---|
38 | { |
---|
39 | test_ostream os(testfile, TEST_STREAM_FLAGS); |
---|
40 | test_oarchive oa(os); |
---|
41 | oa << boost::serialization::make_nvp("aoptional1",aoptional1); |
---|
42 | oa << boost::serialization::make_nvp("aoptional2",aoptional2); |
---|
43 | } |
---|
44 | |
---|
45 | boost::optional<int> aoptional1a(999); |
---|
46 | boost::optional<int> aoptional2a; |
---|
47 | |
---|
48 | { |
---|
49 | test_istream is(testfile, TEST_STREAM_FLAGS); |
---|
50 | test_iarchive ia(is); |
---|
51 | ia >> boost::serialization::make_nvp("aoptional1",aoptional1a); |
---|
52 | ia >> boost::serialization::make_nvp("aoptional2",aoptional2a); |
---|
53 | } |
---|
54 | BOOST_CHECK(aoptional1 == aoptional1a); |
---|
55 | BOOST_CHECK(aoptional2 == aoptional2a); |
---|
56 | |
---|
57 | std::remove(testfile); |
---|
58 | return EXIT_SUCCESS; |
---|
59 | } |
---|
60 | |
---|
61 | // EOF |
---|