]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/test/test_interrupts.cpp
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
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)
9 // should pass compilation and execution
13 #include <boost/config.hpp>
16 #include <algorithm> // equal
17 #include <cstdio> // remove
18 #if defined(BOOST_NO_STDC_NAMESPACE)
24 #include "test_tools.hpp"
25 #include <boost/serialization/nvp.hpp>
26 #include <boost/serialization/split_member.hpp>
27 #include <boost/core/no_exceptions_support.hpp>
28 #include <boost/archive/archive_exception.hpp>
30 struct test_dummy_out
{
31 template<class Archive
>
32 void save(Archive
&, const unsigned int /*version*/) const {
33 throw boost::archive::archive_exception(
34 boost::archive::archive_exception::other_exception
37 template<class Archive
>
38 void load(Archive
& ar
, const unsigned int version
){
40 BOOST_SERIALIZATION_SPLIT_MEMBER()
46 const char * testfile
= boost::archive::tmpnam(NULL
);
47 BOOST_REQUIRE(NULL
!= testfile
);
51 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
54 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
55 bool exception_invoked
= false;
57 oa
<< BOOST_SERIALIZATION_NVP(t
);
59 BOOST_CATCH (boost::archive::archive_exception ae
){
61 boost::archive::archive_exception::other_exception
64 exception_invoked
= true;
67 BOOST_CHECK(exception_invoked
);
69 BOOST_CATCH (boost::archive::archive_exception ae
){}
74 std::remove(testfile
);
78 struct test_dummy_in
{
79 template<class Archive
>
80 void save(Archive
& /* ar */, const unsigned int /*version*/) const {
82 template<class Archive
>
83 void load(Archive
& /* ar */, const unsigned int /*version*/){
84 throw boost::archive::archive_exception(
85 boost::archive::archive_exception::other_exception
88 BOOST_SERIALIZATION_SPLIT_MEMBER()
94 const char * testfile
= boost::archive::tmpnam(NULL
);
95 BOOST_REQUIRE(NULL
!= testfile
);
99 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
101 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
102 oa
<< BOOST_SERIALIZATION_NVP(t
);
107 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
111 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
112 bool exception_invoked
= false;
114 ia
>> BOOST_SERIALIZATION_NVP(t1
);
116 BOOST_CATCH (boost::archive::archive_exception ae
){
118 boost::archive::archive_exception::other_exception
121 exception_invoked
= true;
124 BOOST_CHECK(exception_invoked
);
126 BOOST_CATCH (boost::archive::archive_exception ae
){}
131 std::remove(testfile
);
135 int test_main( int /* argc */, char* /* argv */[] )
138 res
= test_out
<test_dummy_out
>();
139 if (res
!= EXIT_SUCCESS
)
141 res
= test_in
<test_dummy_in
>();
142 if (res
!= EXIT_SUCCESS
)