]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
2 | // test_array.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 | // should pass compilation and execution | |
10 | ||
11 | #include <stdlib.h> | |
12 | ||
13 | #include <boost/config.hpp> | |
14 | #include <cstddef> | |
15 | #include <fstream> | |
16 | #include <algorithm> // equal | |
17 | #include <cstdio> // remove | |
18 | #if defined(BOOST_NO_STDC_NAMESPACE) | |
19 | namespace std{ | |
20 | using ::remove; | |
21 | } | |
22 | #endif | |
23 | ||
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> | |
29 | ||
30 | struct test_dummy_out { | |
31 | template<class Archive> | |
b32b8144 | 32 | void save(Archive &, const unsigned int /*version*/) const { |
7c673cae FG |
33 | throw boost::archive::archive_exception( |
34 | boost::archive::archive_exception::other_exception | |
35 | ); | |
36 | } | |
37 | template<class Archive> | |
38 | void load(Archive & ar, const unsigned int version){ | |
39 | } | |
40 | BOOST_SERIALIZATION_SPLIT_MEMBER() | |
41 | test_dummy_out(){} | |
42 | }; | |
43 | ||
44 | template<class T> | |
45 | int test_out(){ | |
46 | const char * testfile = boost::archive::tmpnam(NULL); | |
47 | BOOST_REQUIRE(NULL != testfile); | |
48 | ||
49 | const T t; | |
50 | { | |
51 | test_ostream os(testfile, TEST_STREAM_FLAGS); | |
52 | { | |
53 | BOOST_TRY { | |
54 | test_oarchive oa(os, TEST_ARCHIVE_FLAGS); | |
55 | bool exception_invoked = false; | |
56 | BOOST_TRY { | |
57 | oa << BOOST_SERIALIZATION_NVP(t); | |
58 | } | |
59 | BOOST_CATCH (boost::archive::archive_exception ae){ | |
60 | BOOST_CHECK( | |
61 | boost::archive::archive_exception::other_exception | |
62 | == ae.code | |
63 | ); | |
64 | exception_invoked = true; | |
65 | } | |
66 | BOOST_CATCH_END | |
67 | BOOST_CHECK(exception_invoked); | |
68 | } | |
69 | BOOST_CATCH (boost::archive::archive_exception ae){} | |
70 | BOOST_CATCH_END | |
71 | } | |
72 | os.close(); | |
73 | } | |
74 | std::remove(testfile); | |
75 | return EXIT_SUCCESS; | |
76 | } | |
77 | ||
78 | struct test_dummy_in { | |
79 | template<class Archive> | |
b32b8144 | 80 | void save(Archive & /* ar */, const unsigned int /*version*/) const { |
7c673cae FG |
81 | } |
82 | template<class Archive> | |
b32b8144 | 83 | void load(Archive & /* ar */, const unsigned int /*version*/){ |
7c673cae FG |
84 | throw boost::archive::archive_exception( |
85 | boost::archive::archive_exception::other_exception | |
86 | ); | |
87 | } | |
88 | BOOST_SERIALIZATION_SPLIT_MEMBER() | |
89 | test_dummy_in(){} | |
90 | }; | |
91 | ||
92 | template<class T> | |
93 | int test_in(){ | |
94 | const char * testfile = boost::archive::tmpnam(NULL); | |
95 | BOOST_REQUIRE(NULL != testfile); | |
96 | ||
97 | const T t; | |
98 | { | |
99 | test_ostream os(testfile, TEST_STREAM_FLAGS); | |
100 | { | |
101 | test_oarchive oa(os, TEST_ARCHIVE_FLAGS); | |
102 | oa << BOOST_SERIALIZATION_NVP(t); | |
103 | } | |
104 | os.close(); | |
105 | } | |
106 | { | |
107 | test_istream is(testfile, TEST_STREAM_FLAGS); | |
108 | { | |
109 | T t1; | |
110 | BOOST_TRY { | |
111 | test_iarchive ia(is, TEST_ARCHIVE_FLAGS); | |
112 | bool exception_invoked = false; | |
113 | BOOST_TRY { | |
114 | ia >> BOOST_SERIALIZATION_NVP(t1); | |
115 | } | |
116 | BOOST_CATCH (boost::archive::archive_exception ae){ | |
117 | BOOST_CHECK( | |
118 | boost::archive::archive_exception::other_exception | |
119 | == ae.code | |
120 | ); | |
121 | exception_invoked = true; | |
122 | } | |
123 | BOOST_CATCH_END | |
124 | BOOST_CHECK(exception_invoked); | |
125 | } | |
126 | BOOST_CATCH (boost::archive::archive_exception ae){} | |
127 | BOOST_CATCH_END | |
128 | } | |
129 | is.close(); | |
130 | } | |
131 | std::remove(testfile); | |
132 | return EXIT_SUCCESS; | |
133 | } | |
134 | ||
135 | int test_main( int /* argc */, char* /* argv */[] ) | |
136 | { | |
137 | int res; | |
138 | res = test_out<test_dummy_out>(); | |
139 | if (res != EXIT_SUCCESS) | |
140 | return EXIT_FAILURE; | |
141 | res = test_in<test_dummy_in>(); | |
142 | if (res != EXIT_SUCCESS) | |
143 | return EXIT_FAILURE; | |
144 | return EXIT_SUCCESS; | |
145 | } | |
146 | ||
147 | // EOF |