]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/assign/test/array.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / assign / test / array.cpp
1 // Boost.Assign library
2 //
3 // Copyright Thorsten Ottosen 2003-2004. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // For more information, see http://www.boost.org/libs/assign/
9 //
10
11 #include <boost/detail/workaround.hpp>
12
13 #if BOOST_WORKAROUND( BOOST_BORLANDC, BOOST_TESTED_AT(0x564) )
14 # pragma warn -8091 // suppress warning in Boost.Test
15 # pragma warn -8057 // unused argument argc/argv in Boost.Test
16 #endif
17
18 #include <boost/assign/list_of.hpp>
19 #include <boost/array.hpp>
20 #include <boost/test/test_tools.hpp>
21 #include <iostream>
22 #include <algorithm>
23 #include <iterator>
24
25 #ifndef BOOST_NO_CXX11_HDR_ARRAY
26 #include <array>
27
28 void check_std_array()
29 {
30 using namespace boost::assign;
31
32 typedef std::array<float,6> Array;
33
34 Array a = list_of(1)(2)(3)(4)(5)(6);
35
36 BOOST_CHECK_EQUAL( a[0], 1 );
37 BOOST_CHECK_EQUAL( a[5], 6 );
38 // last element is implicitly 0
39 Array a2 = list_of(1)(2)(3)(4)(5);
40 BOOST_CHECK_EQUAL( a2[5], 0 );
41 // two last elements are implicitly
42 a2 = list_of(1)(2)(3)(4);
43 BOOST_CHECK_EQUAL( a2[4], 0 );
44 BOOST_CHECK_EQUAL( a2[5], 0 );
45 // too many arguments
46 BOOST_CHECK_THROW( a2 = list_of(1)(2)(3)(4)(5)(6)(7), assignment_exception );
47 }
48
49 #endif
50
51 void check_array()
52 {
53 using namespace boost::assign;
54
55 typedef boost::array<float,6> Array;
56
57
58 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
59 Array a = list_of(1)(2)(3)(4)(5)(6).to_array(a);
60 #else
61 Array a = list_of(1)(2)(3)(4)(5)(6);
62 #endif
63
64 BOOST_CHECK_EQUAL( a[0], 1 );
65 BOOST_CHECK_EQUAL( a[5], 6 );
66 // last element is implicitly 0
67 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
68 Array a2 = list_of(1)(2)(3)(4)(5).to_array(a2);
69 #else
70 Array a2 = list_of(1)(2)(3)(4)(5);
71 #endif
72 BOOST_CHECK_EQUAL( a2[5], 0 );
73 // two last elements are implicitly
74 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
75 a2 = list_of(1))(2)(3)(4).to_array(a2);
76 #else
77 a2 = list_of(1)(2)(3)(4);
78 #endif
79 BOOST_CHECK_EQUAL( a2[4], 0 );
80 BOOST_CHECK_EQUAL( a2[5], 0 );
81 // too many arguments
82 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
83
84 BOOST_CHECK_THROW( a2 = list_of(1)(2)(3)(4)(5)(6)(6).to_array(a2),
85 assignment_exception );
86 #else
87 BOOST_CHECK_THROW( a2 = list_of(1)(2)(3)(4)(5)(6)(7), assignment_exception );
88 #endif
89 }
90
91
92 #include <boost/test/unit_test.hpp>
93 using boost::unit_test::test_suite;
94
95
96 test_suite* init_unit_test_suite( int argc, char* argv[] )
97 {
98 test_suite* test = BOOST_TEST_SUITE( "List Test Suite" );
99
100 test->add( BOOST_TEST_CASE( &check_array ) );
101 #ifndef BOOST_NO_CXX11_HDR_ARRAY
102 test->add( BOOST_TEST_CASE( &check_std_array ) );
103 #endif
104
105 return test;
106 }
107