]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/test/test_native_array.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / serialization / test / test_native_array.cpp
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 #include "test_tools.hpp"
24 #include <boost/core/no_exceptions_support.hpp>
25 #include <boost/archive/archive_exception.hpp>
26 #include <boost/array.hpp>
27
28 #include "A.hpp"
29 #include "A.ipp"
30
31 template <class T>
32 int test_native_array(){
33 const char * testfile = boost::archive::tmpnam(NULL);
34 BOOST_REQUIRE(NULL != testfile);
35
36 // test array of objects
37 const T a_array[10]={T(),T(),T(),T(),T(),T(),T(),T(),T(),T()};
38 const T b_array[2][3]={{T(),T(),T()},{T(),T(),T()}};
39 {
40 test_ostream os(testfile, TEST_STREAM_FLAGS);
41 {
42 test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
43 oa << boost::serialization::make_nvp("a_array", a_array);
44 oa << boost::serialization::make_nvp("b_array", b_array);
45 }
46 os.close();
47 }
48 {
49 T a_array1[10];
50 T b_array1[2][3];
51 test_istream is(testfile, TEST_STREAM_FLAGS);
52 {
53 test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
54 ia >> boost::serialization::make_nvp("a_array", a_array1);
55 ia >> boost::serialization::make_nvp("b_array", b_array1);
56 }
57 is.close();
58 BOOST_CHECK(std::equal(& a_array[0], & a_array[10], & a_array1[0]));
59 BOOST_CHECK(b_array[0][0] == b_array1[0][0]);
60 BOOST_CHECK(b_array[1][0] == b_array1[1][0]);
61 }
62 {
63 T a_array1[9];
64 T b_array1[2][3];
65 test_istream is(testfile, TEST_STREAM_FLAGS);
66 {
67 test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
68 bool exception_invoked = false;
69 BOOST_TRY {
70 ia >> boost::serialization::make_nvp("a_array", a_array1);
71 ia >> boost::serialization::make_nvp("b_array", b_array1);
72 }
73 BOOST_CATCH (boost::archive::archive_exception ae){
74 BOOST_CHECK(
75 boost::archive::archive_exception::array_size_too_short
76 == ae.code
77 );
78 exception_invoked = true;
79 }
80 BOOST_CATCH_END
81 BOOST_CHECK(exception_invoked);
82 }
83 is.close();
84 }
85 std::remove(testfile);
86 return EXIT_SUCCESS;
87 }
88
89 int test_main( int /* argc */, char* /* argv */[] ){
90 int res;
91
92 // native array
93 res = test_native_array<A>();
94 if (res != EXIT_SUCCESS)
95 return EXIT_FAILURE;
96 // test an int array for which optimized versions should be available
97 res = test_native_array<int>();
98 if (res != EXIT_SUCCESS)
99 return EXIT_FAILURE;
100
101 return EXIT_SUCCESS;
102 }
103
104 // EOF