| 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( __BORLANDC__, BOOST_TESTED_AT(0x564) ) |
|---|
| 14 | # pragma warn -8091 // supress 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 | |
|---|
| 26 | |
|---|
| 27 | void check_array() |
|---|
| 28 | { |
|---|
| 29 | using namespace std; |
|---|
| 30 | using namespace boost; |
|---|
| 31 | using namespace boost::assign; |
|---|
| 32 | |
|---|
| 33 | typedef array<float,6> Array; |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) |
|---|
| 37 | Array a = list_of(1)(2)(3)(4)(5)(6).to_array(a); |
|---|
| 38 | #else |
|---|
| 39 | Array a = list_of(1)(2)(3)(4)(5)(6); |
|---|
| 40 | #endif |
|---|
| 41 | |
|---|
| 42 | BOOST_CHECK_EQUAL( a[0], 1 ); |
|---|
| 43 | BOOST_CHECK_EQUAL( a[5], 6 ); |
|---|
| 44 | // last element is implicitly 0 |
|---|
| 45 | #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) |
|---|
| 46 | Array a2 = list_of(1)(2)(3)(4)(5).to_array(a2); |
|---|
| 47 | #else |
|---|
| 48 | Array a2 = list_of(1)(2)(3)(4)(5); |
|---|
| 49 | #endif |
|---|
| 50 | BOOST_CHECK_EQUAL( a2[5], 0 ); |
|---|
| 51 | // two last elements are implicitly |
|---|
| 52 | #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) |
|---|
| 53 | a2 = list_of(1))(2)(3)(4).to_array(a2); |
|---|
| 54 | #else |
|---|
| 55 | a2 = list_of(1)(2)(3)(4); |
|---|
| 56 | #endif |
|---|
| 57 | BOOST_CHECK_EQUAL( a2[4], 0 ); |
|---|
| 58 | BOOST_CHECK_EQUAL( a2[5], 0 ); |
|---|
| 59 | // too many arguments |
|---|
| 60 | #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) |
|---|
| 61 | |
|---|
| 62 | BOOST_CHECK_THROW( a2 = list_of(1)(2)(3)(4)(5)(6)(6).to_array(a2), |
|---|
| 63 | assignment_exception ); |
|---|
| 64 | #else |
|---|
| 65 | BOOST_CHECK_THROW( a2 = list_of(1)(2)(3)(4)(5)(6)(7), assignment_exception ); |
|---|
| 66 | #endif |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | #include <boost/test/unit_test.hpp> |
|---|
| 73 | using boost::unit_test::test_suite; |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | test_suite* init_unit_test_suite( int argc, char* argv[] ) |
|---|
| 77 | { |
|---|
| 78 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); |
|---|
| 79 | |
|---|
| 80 | test->add( BOOST_TEST_CASE( &check_array ) ); |
|---|
| 81 | |
|---|
| 82 | return test; |
|---|
| 83 | } |
|---|
| 84 | |
|---|