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)
19namespace std{
20 using ::remove;
21}
22#endif
23#include "test_tools.hpp"
24#include <boost/core/no_exceptions_support.hpp>
25#include <boost/archive/archive_exception.hpp>
26#include <boost/serialization/boost_array.hpp>
27
28#include "A.hpp"
29#include "A.ipp"
30
31template <class T>
32int test_boost_array(){
33 const char * testfile = boost::archive::tmpnam(NULL);
34 BOOST_REQUIRE(NULL != testfile);
35
36 // test array of objects
37 const boost::array<T,10> a_array = {{T(),T(),T(),T(),T(),T(),T(),T(),T(),T()}};
38 {
39 test_ostream os(testfile, TEST_STREAM_FLAGS);
40 test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
41 oa << boost::serialization::make_nvp("a_array", a_array);
42 }
43 {
44 boost::array<T,10> a_array1;
45 test_istream is(testfile, TEST_STREAM_FLAGS);
46 {
47 test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
48 ia >> boost::serialization::make_nvp("a_array", a_array1);
49 }
50 is.close();
51 BOOST_CHECK(std::equal(a_array.begin(), a_array.end(), a_array1.begin()));
52 }
53 {
54 boost::array<T, 9> a_array1;
55 test_istream is(testfile, TEST_STREAM_FLAGS);
56 {
57 test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
58 bool exception_invoked = false;
59 BOOST_TRY {
60 ia >> boost::serialization::make_nvp("a_array", a_array1);
61 }
62 BOOST_CATCH (boost::archive::archive_exception const& ae){
63 BOOST_CHECK(
64 boost::archive::archive_exception::array_size_too_short
65 == ae.code
66 );
67 exception_invoked = true;
68 }
69 BOOST_CATCH_END
70 BOOST_CHECK(exception_invoked);
71 }
72 is.close();
73 }
74 std::remove(filename: testfile);
75 return EXIT_SUCCESS;
76}
77
78int test_main( int /* argc */, char* /* argv */[] ){
79 int res;
80
81 // boost array
82 res = test_boost_array<A>();
83 if (res != EXIT_SUCCESS)
84 return EXIT_FAILURE;
85 // test an int array for which optimized versions should be available
86 res = test_boost_array<int>();
87 if (res != EXIT_SUCCESS)
88 return EXIT_FAILURE;
89
90 return EXIT_SUCCESS;
91}
92
93// EOF
94

source code of boost/libs/serialization/test/test_boost_array.cpp